From b63ebcd8840b26ed242acdc0192d467660c50107 Mon Sep 17 00:00:00 2001 From: Moss Prescott Date: Fri, 23 Sep 2016 09:38:51 -0400 Subject: [PATCH] good coverage for ASCII in generated paths --- CHANGELOG/revision.md | 1 + .../main/scala/pathy/scalacheck/RandomSeg.scala | 17 +++++++++++------ .../main/scala/pathy/scalacheck/package.scala | 3 +++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 CHANGELOG/revision.md diff --git a/CHANGELOG/revision.md b/CHANGELOG/revision.md new file mode 100644 index 0000000..7761a57 --- /dev/null +++ b/CHANGELOG/revision.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' }