Skip to content

Commit

Permalink
Merge branch 'mossprescott-more-ASCII'
Browse files Browse the repository at this point in the history
  • Loading branch information
alissapajer committed Sep 27, 2016
2 parents 81c4395 + b630aa7 commit 74b5ae6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/0.2.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- improve coverage of ASCII characters in Path generators
17 changes: 11 additions & 6 deletions scalacheck/src/main/scala/pathy/scalacheck/RandomSeg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions scalacheck/src/main/scala/pathy/scalacheck/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ package object scalacheck {
t <- Gen.resize(r, sizeDistributedListOfNonEmpty(g))
} yield (h :: t)
}

val MinPrintableASCII = '\u0020'
val MaxPrintableASCII = '\u007e'
}
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.2.1"
version in ThisBuild := "0.2.2"

0 comments on commit 74b5ae6

Please sign in to comment.