Skip to content

Commit

Permalink
Add addStringCaseless to provide a caseless version of addString
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoultas committed Sep 29, 2022
1 parent b6d9e57 commit 4821597
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions jflex/src/test/java/jflex/core/unicode/CharClassesQuickcheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
@RunWith(JUnitQuickcheck.class)
public class CharClassesQuickcheck {
UnicodeProperties unicodeProperties;

// TODO(lsf): add testing for caseless; needs UnicodeProperties

Expand Down Expand Up @@ -124,6 +125,23 @@ public void addString(CharClasses classes, String s, @From(IntCharGen.class) int
}
}

@Property
public void addStringCaseless(CharClasses classes, String s, @From(IntCharGen.class) int c)
throws UnicodeProperties.UnsupportedUnicodeVersionException {
assumeTrue(!s.toLowerCase().contains(String.valueOf(c)));

classesInit(classes);
classes.makeClass(s, true);
assertThat(classes.invariants()).isTrue();

int cCode = classes.getClassCode(c);
for (int i = 0; i < s.length(); ) {
int ch = s.codePointAt(i);
assertThat(classes.getClassCode(ch)).isNotEqualTo(cCode);
i += Character.charCount(ch);
}
}

@Property
public void normaliseSingle(
CharClasses classes, @InRange(minInt = 0, maxInt = CharClasses.maxChar) int c) {
Expand Down Expand Up @@ -200,4 +218,18 @@ public void classCodesDisjointOrdered(CharClasses classes) {
assertThat(intervals[i].end + 1).isEqualTo(intervals[i + 1].start);
}
}

private void classesInit(CharClasses classes)
throws UnicodeProperties.UnsupportedUnicodeVersionException {
// init classes
unicodeProperties = new UnicodeProperties();
classes.init(
CharClasses.maxChar,
new ILexScan() {
@Override
public UnicodeProperties getUnicodeProperties() {
return unicodeProperties;
}
});
}
}

0 comments on commit 4821597

Please sign in to comment.