Skip to content

Commit

Permalink
unicode string generator close scalaprops#26
Browse files Browse the repository at this point in the history
  • Loading branch information
fommil committed Jan 17, 2022
1 parent 29a51c7 commit 5da69c9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gen/src/main/scala/scalaprops/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@ object Gen extends GenInstances0 {
val asciiString: Gen[String] =
genString(asciiChar)

val unicodeString: Gen[String] = {
val chars = Gen.choose(0, 0x10FFFF).map { cp =>
if (Character.isBmpCodePoint(cp)) {
if (cp < 0xD800) List(cp.toChar)
else List(0)
}
else List(Character.highSurrogate(cp), Character.lowSurrogate(cp))
}
Gen.listOf(chars).map(_.flatten.mkString)
}

implicit val genUnit: Gen[Unit] =
value(())

Expand Down

0 comments on commit 5da69c9

Please sign in to comment.