Skip to content

StringDomain

class in io.proptastic

class StringDomain

Strings of Unicode code points, lengths counted in code points. The simplest character is a; after the letters come digits, the rest of printable ASCII, controls, then the rest of Unicode, so a counterexample shrinks to the plainest characters that still fail.

At random, about one character in four is an edge character, where text handling breaks: the characters escapes and separators use, whitespace beyond the space, the ends of ASCII and Latin-1, characters past the Basic Multilingual Plane (a surrogate pair in a Java string), combining marks and joiners, and the bidi controls. Only the random draw leans to them: a character is still one choice, its place in the order above, so shrinking lowers an edge character toward plain ASCII as far as the failure allows, and a saved counterexample or corpus entry decodes as it always did.

Methods

ofLength

StringDomain ofLength(int n)

Exactly n code points.

ofLength

StringDomain ofLength(Bound... bounds)

One or two bounds: ofLength(atLeast(1), atMost(8)).

nonEmpty

StringDomain nonEmpty()

At least one code point.

nonBlank

StringDomain nonBlank()

At least one character that isn’t whitespace, so text.isBlank() is false in every language: built so, never filtered. A string drawn all whitespace has one of its characters, at a drawn place, drawn again from those that aren’t, so no try is discarded and a counterexample shrinks to "a". Whitespace is Unicode’s White_Space and the separators below the space (decision 96).

singleLine

StringDomain singleLine()

No line breaks: line feed, carriage return, the vertical tab, form feed, next line, and the line and paragraph separators are never drawn, left out by index rather than filtered (decision 96). Other awkward characters stay.

from

StringDomain from(String... alphabets)

Strings of the alphabets’ characters only: strings().from("ACGT"), strings().from(LETTERS, DIGITS) with proptastic’s named alphabets. Each character is drawn as often as another, so one given twice is drawn twice as often, and the first is the simplest, the character a counterexample shrinks to. Its code points are its characters, a surrogate pair as one. An alphabet turns off the awkward characters strings() leans to, so keep strings() where untrusted text comes in.

matching

Domain<String> matching(String regex)

Strings regex matches in full, in Java’s syntax: strings().matching("[A-Z]{3}-\\d{4}"). Each alternative is as likely as another, the first the simplest; a repeat is its least and about 7 more, unless it says its most; each character is as likely as another its class holds, the simplest first, a counterexample shrinking toward a, then the letters, then digits. A part that constrains a match without drawing a character, such as a lookahead, a back reference or a word boundary, is refused, naming it. The regex sets the length and the characters, so it takes no bounds or alphabet of its own.

averageLength

StringDomain averageLength(double n)

About n code points on average, within the bounds: strings().averageLength(30). Without it, a string is its minimum and about 7 more. The longest bound still cuts a draw off, so an average near it comes out a little shorter.

Privacy