[263773] Test cases for context provider

This commit is contained in:
Sebastian Zarnekow 2015-08-17 13:56:20 +02:00
parent 05d60d9c53
commit 7fd786feed
9 changed files with 115 additions and 5 deletions

View file

@ -112,6 +112,9 @@ public interface ISyntacticSequencerPDAProvider {
return input.getType().isStop();
}
});
if (this.stop == null) {
throw new IllegalStateException("Cannot find stop state");
}
}
@Override

View file

@ -463,7 +463,6 @@ Export-Package: org.eclipse.xtext.generator.ecore,
org.eclipse.xtext.parser.fragments.fragmentTestLanguage,
org.eclipse.xtext.parser.fragments.fragmentTestLanguage.impl,
org.eclipse.xtext.parser.fragments.fragmentTestLanguage.util,
org.eclipse.xtext.parser.fragments.parseTreeConstruction,
org.eclipse.xtext.parser.fragments.serializer,
org.eclipse.xtext.parser.fragments.parser.antlr.lexer,
org.eclipse.xtext.grammarinheritance.serializer,

View file

@ -31,7 +31,7 @@ CompositeGeneratorFragment {
}
fragment = grammarAccess.GrammarAccessFragment auto-inject {}
fragment = ecore.EcoreGeneratorFragment auto-inject {}
fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {}
// fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {}
fragment = serializer.SerializerFragment auto-inject {}
fragment = org.eclipse.xtext.idea.generator.parser.antlr.XtextAntlrIDEAGeneratorFragment auto-inject {
options = auto-inject {}

View file

@ -38,7 +38,7 @@ CompositeGeneratorFragment {
}
fragment = grammarAccess.GrammarAccessFragment auto-inject {}
fragment = ecore.EcoreGeneratorFragment auto-inject {}
fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {}
// fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {}
fragment = serializer.SerializerFragment auto-inject {}
fragment = org.eclipse.xtext.idea.generator.parser.antlr.XtextAntlrIDEAGeneratorFragment auto-inject {
options = auto-inject {}

View file

@ -10,7 +10,7 @@ package org.eclipse.xtext.parser.fragments
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
class FragmentExsTest extends AbstractFragmentsTest {
class FragmentsExTest extends AbstractFragmentsTest {
override void setUp() throws Exception {
super.setUp();
with(new FragmentTestLanguageExStandaloneSetup());

View file

@ -15,6 +15,7 @@ import org.eclipse.xtext.generator.*
var projectName = "org.eclipse.xtext.tests"
var runtimeProject = "../${projectName}"
var lineDelimiter = '\n'
var generateDebugData = false
Workflow {
bean = StandaloneSetup {

View file

@ -26,6 +26,7 @@ import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;
import org.eclipse.xtext.util.formallang.Pda;
import org.eclipse.xtext.util.formallang.PdaListFormatter;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.base.Function;
@ -96,6 +97,63 @@ public class ContextPDAProviderTest extends AbstractXtextTests {
super.setUp();
with(XtextStandaloneSetup.class);
}
@Test
@Ignore("TODO implement me, expectation is not correct so far")
public void testFragmentWithAction() throws Exception {
String actual = getParserRule("R: f1=ID F; fragment F returns R: {A.prev=current} f2=ID;");
StringBuilder expected = new StringBuilder();
expected.append("Rule:\n");
expected.append(" start -> {Act.val2=}\n");
expected.append(" val3=ID -> stop\n");
expected.append(" {Act.val2=} -> val3=ID\n");
expected.append("Rule_Act_1:\n");
expected.append(" start -> val1=ID\n");
expected.append(" val1=ID -> stop");
assertEquals(expected.toString(), actual);
}
@Test
@Ignore("TODO implement me, expectation is not correct so far")
public void testFragmentWithActionRecursive() throws Exception {
String actual = getParserRule("R: f1=ID F; fragment F returns R: {A.prev=current} f2=ID F?;");
StringBuilder expected = new StringBuilder();
expected.append("Rule:\n");
expected.append(" start -> a1=ID\n");
expected.append(" 'kw1' -> a2=ID\n");
expected.append(" 'kw2' -> a2=ID\n");
expected.append(" a1=ID -> 'kw1', 'kw2'\n");
expected.append(" a2=ID -> stop");
assertEquals(expected.toString(), actual);
}
@Test
@Ignore("TODO implement me, expectation is not correct so far")
public void testFragmentWithActionTwice() throws Exception {
String actual = getParserRule("R: f1=ID F; fragment F returns R: {A.prev=current} f2=ID {A.prev=current} f2=ID;");
StringBuilder expected = new StringBuilder();
expected.append("Rule:\n");
expected.append(" start -> a1=ID\n");
expected.append(" 'kw1' -> a2=ID\n");
expected.append(" 'kw2' -> a2=ID\n");
expected.append(" a1=ID -> 'kw1', 'kw2'\n");
expected.append(" a2=ID -> stop");
assertEquals(expected.toString(), actual);
}
@Test
@Ignore("TODO implement me, expectation is not correct so far")
public void testFragmentWithActionLoop() throws Exception {
String actual = getParserRule("R: f1=ID F; fragment F returns R: ({A.prev=current} f2=ID)*;");
StringBuilder expected = new StringBuilder();
expected.append("Rule:\n");
expected.append(" start -> a1=ID\n");
expected.append(" 'kw1' -> a2=ID\n");
expected.append(" 'kw2' -> a2=ID\n");
expected.append(" a1=ID -> 'kw1', 'kw2'\n");
expected.append(" a2=ID -> stop");
assertEquals(expected.toString(), actual);
}
@Test
public void testKeywordAlternative() throws Exception {

View file

@ -20,6 +20,7 @@ import org.eclipse.xtext.serializer.analysis.Context2NameFunction;
import org.eclipse.xtext.serializer.analysis.IContextProvider;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.base.Function;
@ -73,6 +74,54 @@ public class ContextProviderTest extends AbstractXtextTests {
String expected = "Rule returns Rule";
assertEquals(expected, actual);
}
@Test
@Ignore("TODO implement in context provider")
public void testFragmentIsNotAContext() throws Exception {
String actual = getContexts("Rule: foo=ID; fragment Fragment: name=ID WCFragment; fragment WCFragment*: desc=STRING;");
String expected = "Rule returns Rule";
assertEquals(expected, actual);
}
@Test
@Ignore("TODO implement in context provider")
public void testActionInFragment() throws Exception {
String actual = getContexts("Rule: foo=ID Fragment; fragment Fragment returns AbstractRule: {AnotherRule.prev=current} name=ID;");
String expected = "Fragment_AnotherRule_0 returns Rule\n" +
"Rule returns AnotherRule";
assertEquals(expected, actual);
}
@Test
@Ignore("TODO implement in context provider")
public void testTwoActionsInFragment() throws Exception {
String actual = getContexts("Rule0: f1=ID Fragment; fragment Fragment returns Rule: {Rule1.prev=current} f2=ID {Rule2.prev=current} f3=ID;");
String expected = "Fragment_Rule1_0 returns Rule0\n" +
"Fragment_Rule2_2 returns Rule1\n" +
"Rule0 returns Rule2";
assertEquals(expected, actual);
}
@Test
@Ignore("TODO implement in context provider")
public void testActionsInFragmentTwoCallers() throws Exception {
String actual = getContexts(
"Rule0: f1=ID Fragment; Rule1: f2=ID Fragment; fragment Fragment returns Rule: {Rule2.prev=current} f3=ID;");
String expected = "Fragment_Rule2_0 returns Rule0, Rule1\n" +
"Rule0 returns Rule2\n" +
"Rule1 returns Rule2";
assertEquals(expected, actual);
}
@Test
@Ignore("TODO implement in context provider")
public void testActionsInFragmentTwoPrecedingActions() throws Exception {
String actual = getContexts(
"Rule0: ({Rule1} f1=ID | {Rule2} f1=STRING) Fragment?; fragment Fragment returns Rule: {Rule3.prev=current} f3=ID;");
String expected = "Fragment_Rule3_0 returns Rule1, Rule2\n" +
"Rule0 returns Rule1, Rule2, Rule3";
assertEquals(expected, actual);
}
@Test
public void testUnassignedAction1() throws Exception {

View file

@ -18,7 +18,7 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({
FragmentsTest.class,
FragmentEagerLinkingTest.class,
FragmentExsTest.class,
FragmentsExTest.class,
FragmentsPlainParsingTest.class,
FragmentExsPlainParsingTest.class,
})