mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
added more test cases for context analysis
This commit is contained in:
parent
0a6b1b69c9
commit
08b240eed4
1 changed files with 56 additions and 0 deletions
|
@ -787,6 +787,7 @@ public class HoistingProcessorTest extends AbstractXtextTests {
|
|||
assertEquals("((" + getSyntaxForKeywordToken("b", 3) + " || ((p0) && (p2))) && (" + getSyntaxForKeywordToken("c", 3) + " || ((p0) && (p3))) && (" + getSyntaxForKeywordToken("d", 3) + " || (p1)))", guard.render());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternativeEmptyAndNonEmptyPaths_expectEofCheck() throws Exception {
|
||||
// @formatter:off
|
||||
String model =
|
||||
|
@ -803,6 +804,7 @@ public class HoistingProcessorTest extends AbstractXtextTests {
|
|||
assertEquals("((" + getSyntaxForKeywordToken("a", 1) + " || (p0)) && (" + getSyntaxForEofToken(1) + " || (p1)))", guard.render());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternativeWithPrefixPath_expectEofCheck() throws Exception {
|
||||
// @formatter:off
|
||||
String model =
|
||||
|
@ -819,6 +821,60 @@ public class HoistingProcessorTest extends AbstractXtextTests {
|
|||
assertEquals("((" + getSyntaxForEofToken(3) + " || (p0)) && (" + getSyntaxForKeywordToken("c", 3) + " || (p1)))", guard.render());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternativeWithPrefixPathAndContextWithSimilarities_expectLookAheadContextCheck() throws Exception {
|
||||
// @formatter:off
|
||||
String model =
|
||||
MODEL_PREAMBLE +
|
||||
"S: a=A 'c' 'd' ;\n" +
|
||||
"A: {A} $$ p0 $$?=> 'a' 'b' \n" +
|
||||
" | {A} $$ p1 $$?=> 'a' 'b' 'c' ;";
|
||||
// @formatter:off
|
||||
XtextResource resource = getResourceFromString(model);
|
||||
Grammar grammar = ((Grammar) resource.getContents().get(0));
|
||||
hoistingProcessor.init(grammar);
|
||||
AbstractRule rule = getRule(grammar, "A");
|
||||
|
||||
HoistingGuard guard = hoistingProcessor.findHoistingGuard(rule.getAlternatives());
|
||||
assertEquals("((" + getSyntaxForKeywordToken("d", 4) + " || (p0)) && (" + getSyntaxForKeywordToken("c", 4) + " || (p1)))", guard.render());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternativeWithPrefixPathAndMultipleContexts_expectNonTrivialContextCheck() throws Exception {
|
||||
// @formatter:off
|
||||
String model =
|
||||
MODEL_PREAMBLE +
|
||||
"S: a=A 'c' \n" +
|
||||
" | a=A 'd' ;\n" +
|
||||
"A: {A} $$ p0 $$?=> 'a' \n" +
|
||||
" | {A} $$ p1 $$?=> 'a' 'b' ;";
|
||||
// @formatter:off
|
||||
XtextResource resource = getResourceFromString(model);
|
||||
Grammar grammar = ((Grammar) resource.getContents().get(0));
|
||||
hoistingProcessor.init(grammar);
|
||||
AbstractRule rule = getRule(grammar, "A");
|
||||
|
||||
HoistingGuard guard = hoistingProcessor.findHoistingGuard(rule.getAlternatives());
|
||||
assertEquals("(((" + getSyntaxForKeywordToken("c", 2) + " && " + getSyntaxForKeywordToken("d", 2) + ") || (p0)) && (" + getSyntaxForKeywordToken("b", 2) + " || (p1)))", guard.render());
|
||||
}
|
||||
|
||||
@Test(expected = TokenAnalysisAbortedException.class)
|
||||
public void testAlternativeWithPrefixPathAndContextIsNotDistince_expectTokenAnalysisAbortedException() throws Exception {
|
||||
// @formatter:off
|
||||
String model =
|
||||
MODEL_PREAMBLE +
|
||||
"S: a=A 'b' 'b' 'b' 'b' 'b' 'b' 'b' 'b' 'b';\n" +
|
||||
"A: {A} $$ p0 $$?=> 'a' \n" +
|
||||
" | {A} $$ p1 $$?=> 'a' 'b' ;";
|
||||
// @formatter:off
|
||||
XtextResource resource = getResourceFromString(model);
|
||||
Grammar grammar = ((Grammar) resource.getContents().get(0));
|
||||
hoistingProcessor.init(grammar);
|
||||
AbstractRule rule = getRule(grammar, "A");
|
||||
|
||||
hoistingProcessor.findHoistingGuard(rule.getAlternatives());
|
||||
}
|
||||
|
||||
@Test(expected = TokenAnalysisAbortedException.class)
|
||||
public void testAlternativeIdenticalPathsInTokenLimit_expectTokenAnalysisAbortedException() throws Exception {
|
||||
// this test shouldn't make problems for symbolic analysis
|
||||
|
|
Loading…
Reference in a new issue