forked from jasder/antlr
Add regression test for exponential complexity of recursive imports
This commit is contained in:
parent
7f577d9209
commit
9d6a6bd3a8
|
@ -1998,4 +1998,36 @@ public class TestPerformance extends BaseTest {
|
|||
Assert.assertEquals("", found);
|
||||
Assert.assertEquals(null, stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test(timeout = 20000)
|
||||
public void testExponentialInclude() {
|
||||
String grammarFormat =
|
||||
"parser grammar Level_%d_%d;\n" +
|
||||
"\n" +
|
||||
"%s import Level_%d_1, Level_%d_2;\n" +
|
||||
"\n" +
|
||||
"rule_%d_%d : EOF;\n";
|
||||
|
||||
System.out.println("dir "+tmpdir);
|
||||
mkdir(tmpdir);
|
||||
|
||||
long startTime = System.nanoTime();
|
||||
|
||||
int levels = 20;
|
||||
for (int level = 0; level < levels; level++) {
|
||||
String leafPrefix = level == levels - 1 ? "//" : "";
|
||||
String grammar1 = String.format(grammarFormat, level, 1, leafPrefix, level + 1, level + 1, level, 1);
|
||||
writeFile(tmpdir, "Level_" + level + "_1.g4", grammar1);
|
||||
if (level > 0) {
|
||||
String grammar2 = String.format(grammarFormat, level, 2, leafPrefix, level + 1, level + 1, level, 1);
|
||||
writeFile(tmpdir, "Level_" + level + "_2.g4", grammar2);
|
||||
}
|
||||
}
|
||||
|
||||
ErrorQueue equeue = antlr("Level_0_1.g4", false);
|
||||
Assert.assertTrue(equeue.errors.isEmpty());
|
||||
|
||||
long endTime = System.nanoTime();
|
||||
System.out.format("%s milliseconds.%n", (endTime - startTime) / 1000000.0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue