1313import static org .sosy_lab .java_smt .api .FormulaType .BooleanType ;
1414import static org .sosy_lab .java_smt .api .FormulaType .IntegerType ;
1515
16- import com .google .common .collect .ImmutableList ;
1716import com .google .common .collect .ImmutableSet ;
1817import com .google .errorprone .annotations .CanIgnoreReturnValue ;
19- import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
2018import java .util .List ;
2119import java .util .Map ;
20+ import java .util .Set ;
2221import java .util .function .BiFunction ;
2322import java .util .function .Function ;
2423import org .junit .Test ;
3534import org .sosy_lab .java_smt .api .visitors .DefaultFormulaVisitor ;
3635import 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+
3942public 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