Skip to content

Commit 2f33842

Browse files
committed
StringFormulaManager: improve tests
1 parent 7612625 commit 2f33842

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

src/org/sosy_lab/java_smt/basicimpl/AbstractStringFormulaManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ private static boolean areAllCodePointsInRange(String str, int lower, int upper)
7575
public static String escapeUnicodeForSmtlib(String input) {
7676
StringBuilder sb = new StringBuilder();
7777
for (int codePoint : input.codePoints().toArray()) {
78-
if (codePoint == 0x5c) {
78+
if (codePoint == 0x5c) { // 0x5c is s single backslash, as char: '\\'
7979
// Backslashes must be escaped, otherwise they may get substituted when reading back
8080
// the results from the model
8181
sb.append("\\u{5c}");
8282
} else if (0x20 <= codePoint && codePoint <= 0x7E) {
8383
sb.appendCodePoint(codePoint); // normal printable chars
8484
} else {
85-
sb.append("\\u{").append(String.format("%x", codePoint)).append("}");
85+
sb.append("\\u{").append(Integer.toHexString(codePoint)).append("}");
8686
}
8787
}
8888
return sb.toString();

src/org/sosy_lab/java_smt/test/StringFormulaManagerTest.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,18 @@ public void testRegexAllCharUnicode() throws SolverException, InterruptedExcepti
212212

213213
// Greek Capital Letter Delta
214214
assertThatFormula(smgr.in(makeStringEscaped("\\u0394"), regexAllChar)).isTautological();
215-
assertThatFormula(smgr.in(makeStringEscaped("Δ"), regexAllChar)).isTautological();
215+
assertThatFormula(smgr.in(smgr.makeString("Δ"), regexAllChar)).isTautological();
216216
// CJK Compatibility Ideograph from Basic Multilingual Plane.
217217
assertThatFormula(smgr.in(makeStringEscaped("\\u{fa6a}"), regexAllChar)).isTautological();
218+
assertThatFormula(smgr.in(smgr.makeString("頻"), regexAllChar)).isTautological();
218219
// Xiangqi Black Horse from Supplementary Multilingual Plane
219220
assertThatFormula(smgr.in(makeStringEscaped("\\u{1fa6a}"), regexAllChar)).isTautological();
220221

221222
// Combining characters are not matched as one character.
222-
assertThatFormula(smgr.in(makeStringEscaped("ab"), regexAllChar)).isUnsatisfiable();
223-
assertThatFormula(smgr.in(makeStringEscaped("abcdefgh"), regexAllChar)).isUnsatisfiable();
224-
assertThatFormula(smgr.in(makeStringEscaped("a\\u0336"), regexAllChar)).isUnsatisfiable();
225-
assertThatFormula(smgr.in(makeStringEscaped("\\n"), regexAllChar)).isUnsatisfiable();
223+
assertThatFormula(smgr.in(smgr.makeString("ab"), regexAllChar)).isUnsatisfiable();
224+
assertThatFormula(smgr.in(smgr.makeString("abcdefgh"), regexAllChar)).isUnsatisfiable();
225+
assertThatFormula(smgr.in(smgr.makeString("a\u0336"), regexAllChar)).isUnsatisfiable();
226+
assertThatFormula(smgr.in(smgr.makeString("\\n"), regexAllChar)).isUnsatisfiable();
226227

227228
StringFormula x = smgr.makeVariable("x");
228229
assertThatFormula(smgr.in(x, smgr.range('a', 'z'))).isSatisfiable();
@@ -966,7 +967,7 @@ public void testStringFromCodePoint() throws SolverException, InterruptedExcepti
966967
}
967968

968969
/**
969-
* Test escapecharacter treatment. Escape characters are treated as a single char! Example:
970+
* Test escape-character treatment. Escape characters are treated as a single char! Example:
970971
* "a\u1234T" has "a" at position 0, "\u1234" at position 1 and "T" at position 2
971972
*
972973
* <p>SMTLIB2 uses an escape sequence for the numerals of the sort: {1234}.
@@ -988,8 +989,8 @@ public void testCharAtWithSpecialCharacters() throws SolverException, Interrupte
988989
String workaround = "au{1234}";
989990
StringFormula au1234WOEscapeCurly = smgr.makeString(workaround);
990991
StringFormula backSlash = smgr.makeString("\\");
991-
StringFormula u1234 = makeStringEscaped("\\u{1234}");
992-
StringFormula au1234b = makeStringEscaped("a\\u{1234}b");
992+
StringFormula u1234 = smgr.makeString("ሴ");
993+
StringFormula au1234b = smgr.makeString("aሴb");
993994

994995
assertEqual(smgr.length(backSlash), imgr.makeNumber(1));
995996
assertEqual(smgr.charAt(au1234b, imgr.makeNumber(0)), a);
@@ -1019,20 +1020,21 @@ public void testCharAtWithSpecialCharacters() throws SolverException, Interrupte
10191020
@Test
10201021
public void testUnicodeEscaping() throws SolverException, InterruptedException {
10211022
// SMTLIB has different representations for the same symbol
1022-
assertEqual(a, makeStringEscaped("\u0061"));
1023+
assertEqual(a, smgr.makeString("\u0061"));
10231024
assertEqual(a, makeStringEscaped("\\u0061"));
10241025
assertEqual(a, makeStringEscaped("\\u{61}"));
10251026
assertEqual(a, makeStringEscaped("\\u{00061}"));
10261027
assertEqual(smgr.length(a), imgr.makeNumber(1));
10271028

1028-
StringFormula u0 = makeStringEscaped("\\u0000");
1029-
assertEqual(u0, makeStringEscaped("\u0000"));
1029+
StringFormula u0 = smgr.makeString("\u0000");
1030+
assertEqual(u0, makeStringEscaped("\\u0000"));
10301031
assertEqual(u0, makeStringEscaped("\\u{0}"));
10311032
assertEqual(u0, makeStringEscaped("\\u{00000}"));
10321033
assertEqual(smgr.length(u0), imgr.makeNumber(1));
10331034

1034-
StringFormula u1 = makeStringEscaped("\\u1234");
1035-
assertEqual(u1, makeStringEscaped("\u1234"));
1035+
StringFormula u1 = smgr.makeString("ሴ");
1036+
assertEqual(u1, smgr.makeString("\u1234"));
1037+
assertEqual(u1, makeStringEscaped("\\u1234"));
10361038
assertEqual(u1, makeStringEscaped("\\u{1234}"));
10371039
assertEqual(u1, makeStringEscaped("\\u{01234}"));
10381040
assertEqual(smgr.length(u1), imgr.makeNumber(1));
@@ -1853,8 +1855,19 @@ public void testStringConcatWUnicode() throws SolverException, InterruptedExcept
18531855
}
18541856

18551857
@Test
1856-
public void testStringSimpleRegex() {
1857-
// TODO
1858+
public void testStringSimpleRegex() throws SolverException, InterruptedException {
1859+
RegexFormula aStarB =
1860+
smgr.concatRegex(ImmutableList.of(smgr.closure(smgr.makeRegex("a")), smgr.makeRegex("b")));
1861+
1862+
assertThatFormula(smgr.in(smgr.makeString("b"), aStarB)).isTautological();
1863+
assertThatFormula(smgr.in(smgr.makeString("ab"), aStarB)).isTautological();
1864+
assertThatFormula(smgr.in(smgr.makeString("aaaaab"), aStarB)).isTautological();
1865+
assertThatFormula(smgr.in(smgr.makeString("aaaaaaaaaab"), aStarB)).isTautological();
1866+
1867+
assertThatFormula(smgr.in(smgr.makeString(""), aStarB)).isUnsatisfiable();
1868+
assertThatFormula(smgr.in(smgr.makeString("a"), aStarB)).isUnsatisfiable();
1869+
assertThatFormula(smgr.in(smgr.makeString("abaaab"), aStarB)).isUnsatisfiable();
1870+
assertThatFormula(smgr.in(smgr.makeString("abb"), aStarB)).isUnsatisfiable();
18581871
}
18591872

18601873
@Test

0 commit comments

Comments
 (0)