diff --git a/CHANGELOG/0.2.2.md b/CHANGELOG/0.2.2.md new file mode 100644 index 0000000..7761a57 --- /dev/null +++ b/CHANGELOG/0.2.2.md @@ -0,0 +1 @@ +- improve coverage of ASCII characters in Path generators \ No newline at end of file diff --git a/scalacheck/src/main/scala/pathy/scalacheck/RandomSeg.scala b/scalacheck/src/main/scala/pathy/scalacheck/RandomSeg.scala index 5c54a6b..6cece38 100644 --- a/scalacheck/src/main/scala/pathy/scalacheck/RandomSeg.scala +++ b/scalacheck/src/main/scala/pathy/scalacheck/RandomSeg.scala @@ -22,19 +22,24 @@ import org.scalacheck.Gen import scalaz.Show +/** Newtype for path segment strings with a generator that produces mostly + * alphanumeric, then any printable ASCII char, with slightly more `.` and `/` + * characters (because they tend to be problematic for encoders), and finally + * an occasional char from anywhere in Unicode. */ private[scalacheck] final case class RandomSeg(str: String) extends AnyVal private[scalacheck] object RandomSeg { - implicit val randomSegArbitrary: Arbitrary[RandomSeg] = + implicit val arbitrary: Arbitrary[RandomSeg] = Arbitrary { Gen.nonEmptyListOf(Gen.frequency( - 100 -> Gen.alphaNumChar, - 10 -> Gen.const('.'), - 10 -> Gen.const('/'), - 5 -> Arbitrary.arbitrary[Char] + 50 -> Gen.alphaChar, + 25 -> Gen.choose(MinPrintableASCII, MaxPrintableASCII), + 10 -> Gen.const('.'), + 10 -> Gen.const('/'), + 5 -> Arbitrary.arbitrary[Char] )) map (cs => RandomSeg(cs.mkString)) } - implicit val randomSegShow: Show[RandomSeg] = + implicit val show: Show[RandomSeg] = Show.shows(_.str) } diff --git a/scalacheck/src/main/scala/pathy/scalacheck/package.scala b/scalacheck/src/main/scala/pathy/scalacheck/package.scala index 119e860..192a0d4 100644 --- a/scalacheck/src/main/scala/pathy/scalacheck/package.scala +++ b/scalacheck/src/main/scala/pathy/scalacheck/package.scala @@ -57,4 +57,7 @@ package object scalacheck { t <- Gen.resize(r, sizeDistributedListOfNonEmpty(g)) } yield (h :: t) } + + val MinPrintableASCII = '\u0020' + val MaxPrintableASCII = '\u007e' } diff --git a/version.sbt b/version.sbt index a500ff9..11d1a4c 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.2.1" +version in ThisBuild := "0.2.2"