Skip to content

Commit 07c0199

Browse files
Simplify VariableNamesTest classes
1 parent 51231a4 commit 07c0199

File tree

4 files changed

+31
-223
lines changed

4 files changed

+31
-223
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void init() {
120120
* <p>This function is stricter than {@link FormulaCreator#isValidName(String)} and won't allow
121121
* names such as <code>"a \nb"</code> without any SMTLIB quotes.
122122
*/
123-
private static boolean isValid(String pSymbol) {
123+
static boolean isValid(String pSymbol) {
124124
if (pSymbol.length() >= 2 && pSymbol.startsWith("|") && pSymbol.endsWith("|")) {
125125
return FormulaCreator.isValidName(dequote(pSymbol));
126126
} else {
@@ -134,12 +134,12 @@ private static boolean isValid(String pSymbol) {
134134
*
135135
* <p>Assumes that the symbol is not already quoted.
136136
*/
137-
private static String addQuotes(String pSymbol) {
137+
static String addQuotes(String pSymbol) {
138138
return "|" + pSymbol + "|";
139139
}
140140

141141
/** Returns <code>True</code> if the symbol is quoted */
142-
private static boolean hasQuotes(String pSymbol) {
142+
static boolean hasQuotes(String pSymbol) {
143143
return pSymbol.length() >= 2 && pSymbol.startsWith("|") && pSymbol.endsWith("|");
144144
}
145145

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,21 @@
1010

1111
import static com.google.common.truth.Truth.assertThat;
1212

13-
import com.google.common.collect.Lists;
14-
import java.util.List;
1513
import org.junit.Test;
1614

17-
/** inherits many tests from {@link VariableNamesTest}. */
18-
public class VariableNamesEscaperTest extends VariableNamesTest {
19-
20-
@Override
21-
protected List<String> getAllNames() {
22-
return Lists.transform(super.getAllNames(), mgr::escape);
23-
}
15+
public class VariableNamesEscaperTest extends SolverBasedTest0 {
2416

2517
@Test
2618
public void testEscapeUnescape() {
27-
for (String var : getAllNames()) {
19+
for (String var : VariableNamesTest.getAllNames()) {
2820
assertThat(mgr.unescape(mgr.escape(var))).isEqualTo(var);
2921
assertThat(mgr.unescape(mgr.unescape(mgr.escape(mgr.escape(var))))).isEqualTo(var);
3022
}
3123
}
3224

3325
@Test
3426
public void testDoubleEscapeUnescape() {
35-
for (String var : getAllNames()) {
27+
for (String var : VariableNamesTest.getAllNames()) {
3628
assertThat(mgr.unescape(mgr.escape(var))).isEqualTo(var);
3729
assertThat(mgr.unescape(mgr.unescape(mgr.escape(mgr.escape(var))))).isEqualTo(var);
3830
}

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

Lines changed: 0 additions & 72 deletions
This file was deleted.

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

Lines changed: 25 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
import static org.sosy_lab.java_smt.api.FormulaType.BooleanType;
1414
import static org.sosy_lab.java_smt.api.FormulaType.IntegerType;
1515

16-
import com.google.common.collect.ImmutableList;
1716
import com.google.common.collect.ImmutableSet;
1817
import com.google.errorprone.annotations.CanIgnoreReturnValue;
19-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2018
import java.util.List;
2119
import java.util.Map;
20+
import java.util.Set;
2221
import java.util.function.BiFunction;
2322
import java.util.function.Function;
2423
import org.junit.Test;
@@ -35,137 +34,26 @@
3534
import org.sosy_lab.java_smt.api.visitors.DefaultFormulaVisitor;
3635
import org.sosy_lab.java_smt.basicimpl.FormulaCreator;
3736

38-
@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE")
37+
// TODO Reduce the number of tests in this class.
38+
// For variable name escaping we don't have to try every combination of Sort x Name. It should be
39+
// enough to test the names once, and then check that escaping is applied for variables/ufs of all
40+
// types.
41+
3942
public class VariableNamesTest extends SolverBasedTest0.ParameterizedSolverBasedTest0 {
4043

41-
public static final ImmutableList<String> NAMES =
42-
ImmutableList.of(
43-
"java-smt",
44-
"JavaSMT",
45-
"sosylab",
46-
"test",
47-
"foo",
48-
"bar",
49-
"baz",
50-
"declare",
51-
"(exit)",
52-
"!=",
53-
"~",
54-
",",
55-
".",
56-
":",
57-
" ",
58-
" ",
59-
"(",
60-
")",
61-
"[",
62-
"]",
63-
"{",
64-
"}",
65-
"[]",
66-
"\"",
67-
"\"\"",
68-
"\"\"\"",
69-
"'",
70-
"''",
71-
"'''",
72-
"\n",
73-
"\t",
74-
"\u0000",
75-
"\u0001",
76-
"\u1234",
77-
"\u2e80",
78-
" this is a quoted symbol ",
79-
" so is \n this one ",
80-
" \" can occur too ",
81-
" af klj ^*0 asfe2 (&*)&(#^ $ > > >?\" ’]]984");
82-
83-
private static final ImmutableSet<String> FURTHER_SMTLIB2_KEYWORDS =
84-
ImmutableSet.of(
85-
"let",
86-
"forall",
87-
"exists",
88-
"match",
89-
"Bool",
90-
"continued-execution",
91-
"error",
92-
"immediate-exit",
93-
"incomplete",
94-
"logic",
95-
"memout",
96-
"sat",
97-
"success",
98-
"theory",
99-
"unknown",
100-
"unsupported",
101-
"unsat",
102-
"_",
103-
"as",
104-
"BINARY",
105-
"DECIMAL",
106-
"HEXADECIMAL",
107-
"NUMERAL",
108-
"par",
109-
"STRING",
110-
"assert",
111-
"check-sat",
112-
"check-sat-assuming",
113-
"declare-const",
114-
"declare-datatype",
115-
"declare-datatypes",
116-
"declare-fun",
117-
"declare-sort",
118-
"define-fun",
119-
"define-fun-rec",
120-
"define-sort",
121-
"echo",
122-
"exit",
123-
"get-assertions",
124-
"get-assignment",
125-
"get-info",
126-
"get-model",
127-
"get-option",
128-
"get-proof",
129-
"get-unsat-assumptions",
130-
"get-unsat-core",
131-
"get-value",
132-
"pop",
133-
"push",
134-
"reset",
135-
"reset-assertions",
136-
"set-info",
137-
"set-logic",
138-
"set-option");
139-
140-
/**
141-
* Some special chars are not allowed to appear in symbol names. See {@link
142-
* FormulaCreator#DISALLOWED_CHARACTERS}.
143-
*/
144-
@SuppressWarnings("javadoc")
145-
public static final ImmutableSet<String> UNSUPPORTED_NAMES =
146-
ImmutableSet.of(
147-
"|",
148-
"||",
149-
"|||",
150-
"|test",
151-
"|test|",
152-
"t|e|s|t",
153-
"\\",
154-
"\\s",
155-
"\\|\\|",
156-
"| this is a quoted symbol |",
157-
"| so is \n this one |",
158-
"| \" can occur too |",
159-
"| af klj ^*0 asfe2 (&*)&(#^ $ > > >?\" ’]]984|");
160-
161-
protected List<String> getAllNames() {
162-
return ImmutableList.<String>builder()
163-
.addAll(NAMES)
164-
.addAll(FormulaCreator.RESERVED)
165-
.addAll(FormulaCreator.DISALLOWED_CHARACTER_REPLACEMENT.values())
166-
.addAll(FURTHER_SMTLIB2_KEYWORDS)
167-
.addAll(UNSUPPORTED_NAMES)
168-
.build();
44+
static Set<String> getAllNames() {
45+
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
46+
for (String symbol : ParserSymbolsEscapedTest.TEST_SYMBOLS) {
47+
for (String variant :
48+
ImmutableSet.of(
49+
symbol,
50+
ParserSymbolsEscapedTest.addQuotes(symbol),
51+
FormulaCreator.escapeName(symbol),
52+
ParserSymbolsEscapedTest.addQuotes(FormulaCreator.escapeName(symbol)))) {
53+
builder.add(variant);
54+
}
55+
}
56+
return builder.build();
16957
}
17058

17159
@CanIgnoreReturnValue
@@ -211,7 +99,7 @@ private <T extends Formula> void testName0(
21199
String dump = mgr.dumpFormula(eq.apply(var, var)).toString();
212100

213101
// Adding SMTLIB quotes to the name should make it illegal
214-
assertThat(mgr.isValidName("|" + name + "|")).isFalse();
102+
assertThat(mgr.isValidName(ParserSymbolsEscapedTest.addQuotes(name))).isFalse();
215103
}
216104

217105
@Test
@@ -277,7 +165,7 @@ public void testNameIntArray() throws SolverException, InterruptedException {
277165
public void testNameBvArray() throws SolverException, InterruptedException {
278166
requireBitvectors();
279167
requireArrays();
280-
for (String name : NAMES) {
168+
for (String name : getAllNames()) {
281169
testName0(
282170
name,
283171
s ->
@@ -293,7 +181,7 @@ public void testNameBvArray() throws SolverException, InterruptedException {
293181
@Test
294182
public void testNameUF1Bool() throws SolverException, InterruptedException {
295183
requireIntegers();
296-
for (String name : NAMES) {
184+
for (String name : getAllNames()) {
297185
testName0(
298186
name,
299187
s -> fmgr.declareAndCallUF(s, BooleanType, imgr.makeNumber(0)),
@@ -305,7 +193,7 @@ public void testNameUF1Bool() throws SolverException, InterruptedException {
305193
@Test
306194
public void testNameUF1Int() throws SolverException, InterruptedException {
307195
requireIntegers();
308-
for (String name : NAMES) {
196+
for (String name : getAllNames()) {
309197
testName0(
310198
name, s -> fmgr.declareAndCallUF(s, IntegerType, imgr.makeNumber(0)), imgr::equal, true);
311199
}
@@ -327,7 +215,7 @@ public void testNameUFBv() throws SolverException, InterruptedException {
327215
public void testNameUF2Bool() throws SolverException, InterruptedException {
328216
requireIntegers();
329217
IntegerFormula zero = imgr.makeNumber(0);
330-
for (String name : NAMES) {
218+
for (String name : getAllNames()) {
331219
testName0(
332220
name, s -> fmgr.declareAndCallUF(s, BooleanType, zero, zero), bmgr::equivalence, true);
333221
}
@@ -337,7 +225,7 @@ public void testNameUF2Bool() throws SolverException, InterruptedException {
337225
public void testNameUF2Int() throws SolverException, InterruptedException {
338226
requireIntegers();
339227
IntegerFormula zero = imgr.makeNumber(0);
340-
for (String name : NAMES) {
228+
for (String name : getAllNames()) {
341229
testName0(name, s -> fmgr.declareAndCallUF(s, IntegerType, zero, zero), imgr::equal, true);
342230
}
343231
}

0 commit comments

Comments
 (0)