Skip to content

Commit 09eca10

Browse files
committed
Fix match teaclet tests
1 parent 2d07e52 commit 09eca10

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

key.core/src/test/java/de/uka/ilkd/key/rule/TacletForTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,22 @@ public static Sort sortLookup(String name) {
198198
return getSorts().lookup(new Name(name));
199199
}
200200

201+
public static JTerm parseTerm(String termstr, Services services, NamespaceSet nss) {
202+
if (termstr.isEmpty()) {
203+
return null;
204+
}
205+
206+
try {
207+
KeyIO io = new KeyIO(services, nss);
208+
// TacletForTests.getAbbrevs()
209+
return io.parseExpression(termstr);
210+
} catch (Exception e) {
211+
fail("Exception occurred while parsing of " + termstr, e);
212+
return null;
213+
}
214+
215+
}
216+
201217
public static JTerm parseTerm(String termstr, Services services) {
202218
if (termstr.isEmpty()) {
203219
return null;

key.core/src/test/java/de/uka/ilkd/key/rule/TestMatchTaclet.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public void setUp() {
6868
TacletForTests.parse();
6969

7070
services = TacletForTests.services();
71+
LocationVariable i = new LocationVariable(new ProgramElementName("i"),
72+
services.getJavaInfo().getKeYJavaType("int"));
73+
services.getNamespaces().programVariables().add(i);
74+
7175
TB = services.getTermBuilder();
7276

7377
all_left = (FindTaclet) TacletForTests.getTaclet("TestMatchTaclet_for_all").taclet();
@@ -282,18 +286,17 @@ public void testConflict() {
282286
// test match of update terms
283287
@Test
284288
public void testUpdateMatch() {
285-
LocationVariable i = new LocationVariable(new ProgramElementName("i"),
286-
services.getJavaInfo().getKeYJavaType("int"));
287-
services.getNamespaces().programVariables().add(i);
288-
JTerm match = TacletForTests.parseTerm("\\<{}\\>{i:=2}(\\forall nat z; (q1(z)))");
289+
JTerm match = TacletForTests.parseTerm("\\<{}\\>{i:=2}(\\forall nat z; (q1(z)))", services,
290+
services.getNamespaces());
289291
match = match.sub(0);
290292
assertNotNull(
291293
all_left.getMatcher().matchFind(match, EMPTY_MATCHCONDITIONS, services),
292294
"Instantiations should be found as updates can be ignored if "
293295
+ "only the term that is matched has an update and the "
294296
+ "template it is matched to has none.");
295297

296-
JTerm match2 = TacletForTests.parseTerm("\\<{int i;}\\>{i:=Z(2(#))} true");
298+
JTerm match2 = TacletForTests.parseTerm("\\<{int i;}\\>{i:=Z(2(#))} true", services,
299+
services.getNamespaces());
297300
match2 = match2.sub(0);
298301
assertNotNull(assign_n.getMatcher().matchFind(match2, EMPTY_MATCHCONDITIONS,
299302
services), "Instantiations should be found.");
@@ -302,7 +305,7 @@ public void testUpdateMatch() {
302305

303306
@Test
304307
public void testProgramMatchEmptyBlock() {
305-
JTerm match = TacletForTests.parseTerm("\\<{ }\\>true ");
308+
JTerm match = TacletForTests.parseTerm("\\<{ }\\>true ", services);
306309
FindTaclet taclet = (FindTaclet) TacletForTests.getTaclet("empty_diamond").taclet();
307310
MatchResultInfo mc =
308311
(taclet.getMatcher().matchFind(match, EMPTY_MATCHCONDITIONS, services));
@@ -317,7 +320,7 @@ public void testProgramMatchEmptyBlock() {
317320

318321
assertNotNull(mc);
319322

320-
match = TacletForTests.parseTerm("\\<{ {int i = 0;} }\\>true ");
323+
match = TacletForTests.parseTerm("\\<{ {int i = 0;} }\\>true ", services);
321324
mc = (taclet.getMatcher().matchFind(match, EMPTY_MATCHCONDITIONS,
322325
services));
323326

@@ -388,7 +391,8 @@ null, new LocationVariable(new ProgramElementName("testVar"),
388391
(taclet.getMatcher().matchFind(match, EMPTY_MATCHCONDITIONS, services));
389392
assertNotNull(mc, "Method-Frame should match");
390393

391-
JTerm termWithPV = TacletForTests.parseTerm("\\<{int i;}\\>i=0");
394+
JTerm termWithPV =
395+
TacletForTests.parseTerm("\\<{int i;}\\>i=0", services, services.getNamespaces());
392396
match = TacletForTests.parseTerm("\\<{return 2;}\\>true ");
393397
prg = (StatementBlock) match.javaBlock().program();
394398
mframe = new MethodFrame((IProgramVariable) termWithPV.sub(0).sub(0).op(), ec, prg);
@@ -468,7 +472,8 @@ public void testInsequentStateRestriction() {
468472
FindTaclet unrestrictedTaclet =
469473
(FindTaclet) TacletForTests.getTaclet("testInsequentState_2").taclet();
470474

471-
JTerm match = TacletForTests.parseTerm("{ i := 0 } (i = 0)");
475+
JTerm match =
476+
TacletForTests.parseTerm("{ i := 0 } (i = 0)", services, services.getNamespaces());
472477
MatchResultInfo mc = (restrictedTaclet.getMatcher().matchFind(match,
473478
EMPTY_MATCHCONDITIONS, services));
474479
assertNull(mc, "Test inSequentState failed: matched on term with update prefix");
@@ -477,7 +482,7 @@ public void testInsequentStateRestriction() {
477482
EMPTY_MATCHCONDITIONS, services));
478483
assertNotNull(mc, "Test inSequentState failed: did not match on term with update prefix");
479484

480-
match = TacletForTests.parseTerm("i = 0");
485+
match = TacletForTests.parseTerm("i = 0", services, services.getNamespaces());
481486
mc = (restrictedTaclet.getMatcher().matchFind(match, EMPTY_MATCHCONDITIONS,
482487
services));
483488
assertNotNull(mc,

0 commit comments

Comments
 (0)