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
Sam Halliday committed Jan 11, 2022
1 parent 29a51c7 commit 85ad4f8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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,14 @@ 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)) List(cp.toChar)
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 85ad4f8

Please sign in to comment.