@@ -191,6 +191,7 @@ public static List<Object[]> getAllCombinations() {
191
191
.addAll (NAMES )
192
192
.addAll (AbstractFormulaManager .BASIC_OPERATORS )
193
193
.addAll (AbstractFormulaManager .SMTLIB2_KEYWORDS )
194
+ .addAll (AbstractFormulaManager .DISALLOWED_CHARACTER_REPLACEMENT .values ())
194
195
.addAll (FURTHER_SMTLIB2_KEYWORDS )
195
196
.addAll (UNSUPPORTED_NAMES )
196
197
.build ();
@@ -209,33 +210,41 @@ protected Solvers solverToUse() {
209
210
return solver ;
210
211
}
211
212
213
+ boolean allowInvalidNames () {
214
+ return true ;
215
+ }
216
+
217
+ String getVarname () {
218
+ return varname ;
219
+ }
220
+
212
221
@ CanIgnoreReturnValue
213
- private <T extends Formula > T createVariableWith (Function <String , T > creator ) {
222
+ private <T extends Formula > T createVariableWith (Function <String , T > creator , String name ) {
214
223
final T result ;
215
- if (!mgr .isValidName (varname )) {
224
+ if (allowInvalidNames () && !mgr .isValidName (name )) {
216
225
try {
217
- result = creator .apply (varname );
226
+ result = creator .apply (name );
218
227
fail ();
219
228
} catch (IllegalArgumentException e ) {
220
229
throw new AssumptionViolatedException ("unsupported variable name" , e );
221
230
}
222
231
} else {
223
- result = creator .apply (varname );
232
+ result = creator .apply (name );
224
233
}
225
234
return result ;
226
235
}
227
236
228
237
@ Test
229
238
public void testBoolVariable () {
230
- createVariableWith (bmgr ::makeVariable );
239
+ createVariableWith (bmgr ::makeVariable , getVarname () );
231
240
}
232
241
233
242
private <T extends Formula > void testName0 (
234
243
Function <String , T > creator , BiFunction <T , T , BooleanFormula > eq , boolean isUF )
235
244
throws SolverException , InterruptedException {
236
245
237
246
// create a variable
238
- T var = createVariableWith (creator );
247
+ T var = createVariableWith (creator , getVarname () );
239
248
240
249
// check whether it exists with the given name
241
250
Map <String , Formula > map = mgr .extractVariables (var );
@@ -244,10 +253,10 @@ private <T extends Formula> void testName0(
244
253
map = mgr .extractVariablesAndUFs (var );
245
254
}
246
255
assertThat (map ).hasSize (1 );
247
- assertThat (map ).containsEntry (varname , var );
256
+ assertThat (map ).containsEntry (getVarname () , var );
248
257
249
258
// check whether we can create the same variable again
250
- T var2 = createVariableWith (creator );
259
+ T var2 = createVariableWith (creator , getVarname () );
251
260
// for simple formulas, we can expect a direct equality
252
261
// (for complex formulas this is not satisfied)
253
262
assertThat (var2 ).isEqualTo (var );
@@ -265,11 +274,12 @@ private <T extends Formula> void testName0(
265
274
@ SuppressWarnings ("unused" )
266
275
String dump = mgr .dumpFormula (eq .apply (var , var )).toString ();
267
276
268
- // try to create a new (!) variable with a different name, the escaped previous name.
269
- varname = "|" + varname + "|" ;
270
- @ SuppressWarnings ("unused" )
271
- T var3 = createVariableWith (creator );
272
- fail ();
277
+ if (allowInvalidNames ()) {
278
+ // try to create a new (!) variable with a different name, the escaped previous name.
279
+ @ SuppressWarnings ("unused" )
280
+ T var3 = createVariableWith (creator , "|" + getVarname () + "|" );
281
+ fail ();
282
+ }
273
283
}
274
284
275
285
@ Test
@@ -336,7 +346,7 @@ public void testNameUF2Int() throws SolverException, InterruptedException {
336
346
public void testNameExists () {
337
347
requireQuantifiers ();
338
348
339
- IntegerFormula var = createVariableWith (imgr ::makeVariable );
349
+ IntegerFormula var = createVariableWith (imgr ::makeVariable , getVarname () );
340
350
IntegerFormula zero = imgr .makeNumber (0 );
341
351
BooleanFormula exists = qmgr .exists (var , imgr .equal (var , zero ));
342
352
@@ -356,7 +366,7 @@ public Void visitQuantifier(
356
366
for (Formula f : pBoundVariables ) {
357
367
Map <String , Formula > map = mgr .extractVariables (f );
358
368
assertThat (map ).hasSize (1 );
359
- assertThat (map ).containsEntry (varname , f );
369
+ assertThat (map ).containsEntry (getVarname () , f );
360
370
}
361
371
return null ;
362
372
}
@@ -370,7 +380,7 @@ protected Void visitDefault(Formula pF) {
370
380
371
381
@ Test
372
382
public void testBoolVariableNameInVisitor () {
373
- BooleanFormula var = createVariableWith (bmgr ::makeVariable );
383
+ BooleanFormula var = createVariableWith (bmgr ::makeVariable , getVarname () );
374
384
375
385
bmgr .visit (
376
386
var ,
@@ -382,65 +392,66 @@ protected Void visitDefault() {
382
392
383
393
@ Override
384
394
public Void visitAtom (BooleanFormula pAtom , FunctionDeclaration <BooleanFormula > pDecl ) {
385
- assertThat (pDecl .getName ()).isEqualTo (varname );
395
+ assertThat (pDecl .getName ()).isEqualTo (getVarname () );
386
396
return null ;
387
397
}
388
398
});
389
399
}
390
400
391
401
@ Test
392
402
public void testBoolVariableDump () {
393
- BooleanFormula var = createVariableWith (bmgr ::makeVariable );
403
+ BooleanFormula var = createVariableWith (bmgr ::makeVariable , getVarname () );
394
404
@ SuppressWarnings ("unused" )
395
405
String dump = mgr .dumpFormula (var ).toString ();
396
406
}
397
407
398
408
@ Test
399
409
public void testEqBoolVariableDump () {
400
- BooleanFormula var = createVariableWith (bmgr ::makeVariable );
410
+ BooleanFormula var = createVariableWith (bmgr ::makeVariable , getVarname () );
401
411
@ SuppressWarnings ("unused" )
402
412
String dump = mgr .dumpFormula (bmgr .equivalence (var , var )).toString ();
403
413
}
404
414
405
415
@ Test
406
416
public void testIntVariable () {
407
- createVariableWith (imgr ::makeVariable );
417
+ createVariableWith (imgr ::makeVariable , getVarname () );
408
418
}
409
419
410
420
@ Test
411
421
public void testInvalidRatVariable () {
412
422
requireRationals ();
413
- createVariableWith (rmgr ::makeVariable );
423
+ createVariableWith (rmgr ::makeVariable , getVarname () );
414
424
}
415
425
416
426
@ Test
417
427
public void testBVVariable () {
418
428
requireBitvectors ();
419
- createVariableWith (v -> bvmgr .makeVariable (4 , v ));
429
+ createVariableWith (v -> bvmgr .makeVariable (4 , v ), getVarname () );
420
430
}
421
431
422
432
@ Test
423
433
public void testInvalidFloatVariable () {
424
434
requireFloats ();
425
435
createVariableWith (
426
- v -> fpmgr .makeVariable (v , FormulaType .getSinglePrecisionFloatingPointType ()));
436
+ v -> fpmgr .makeVariable (v , FormulaType .getSinglePrecisionFloatingPointType ()),
437
+ getVarname ());
427
438
}
428
439
429
440
@ Test
430
441
public void testArrayVariable () {
431
442
requireArrays ();
432
- createVariableWith (v -> amgr .makeArray (v , IntegerType , IntegerType ));
443
+ createVariableWith (v -> amgr .makeArray (v , IntegerType , IntegerType ), getVarname () );
433
444
}
434
445
435
446
@ Test
436
447
public void sameBehaviorTest () {
437
- if (mgr .isValidName (varname )) {
448
+ if (mgr .isValidName (getVarname () )) {
438
449
// should pass without exception
439
- AbstractFormulaManager .checkVariableName (varname );
450
+ AbstractFormulaManager .checkVariableName (getVarname () );
440
451
} else {
441
452
try {
442
453
// should throw exception
443
- AbstractFormulaManager .checkVariableName (varname );
454
+ AbstractFormulaManager .checkVariableName (getVarname () );
444
455
fail ();
445
456
} catch (IllegalArgumentException e ) {
446
457
}
0 commit comments