-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unicode String Gen #26
Comments
Why don't you just use if (Character.isValidCodePoint(i)) String.valueOf(Character.toChars(i)) else /* retry code */ |
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)
} references
probably want to have something like this to handle the surrogates during shrinking: implicit val strShrinker: Shrink[String] = Shrink.shrink { txt =>
if (txt.isEmpty) Stream.empty[String]
else if (txt.length == 1) Stream("")
else {
val a = if (txt.head.isSurrogate) txt.drop(2) else txt.drop(1)
val b = if (txt.last.isSurrogate) txt.take(txt.length - 2) else txt.take(txt.length - 1)
Stream(a, b).filter(_ != txt).distinct
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: