[tests] Enabled a number of previously disabled test cases

Replaced commented code with more explicit @Ignore annotations in test classes
This commit is contained in:
Sebastian Zarnekow 2012-03-13 11:30:28 +01:00
parent 2c6128873a
commit d83d4f8365
11 changed files with 353 additions and 270 deletions

View file

@ -10,25 +10,33 @@ package org.eclipse.xtext.generator;
//import org.eclipse.xtext.generator.generatorTestLanguage.GeneratorTestLanguagePackage;
//import org.eclipse.xtext.generator.generatorTestLanguage.Rule;
import org.eclipse.xtext.junit4.AbstractXtextTests;
import org.junit.Ignore;
import org.junit.Test;
/**
* You'll have to regenerate the test languages with the org.eclipse.xtext.generator.GeneratorTestLanguage
* enabled in the workflow.
* @author Sebastian Zarnekow - Initial contribution and API
*/
public abstract class AbstractLargeMetamodelTest extends AbstractXtextTests {
// @Override
// public void setUp() throws Exception {
// super.setUp();
@Override
public void setUp() throws Exception {
super.setUp();
// with(GeneratorTestLanguageStandaloneSetup.class);
// }
//
// @Test public void testRuleClass() {
}
@Test
@Ignore("see class comment")
public void testRuleClass() {
// Class<Rule> ruleClass = Rule.class;
// assertNotNull(ruleClass);
// }
//
// @Test public void testEPackage() {
}
@Test
@Ignore("see class comment")
public void testEPackage() {
// GeneratorTestLanguagePackage instance = GeneratorTestLanguagePackage.eINSTANCE;
// assertNotNull(instance);
// }
}
}

View file

@ -38,38 +38,43 @@ public class XtextTokenStreamTest extends Assert implements TokenSource {
}
}
// @Test public void test_smallFile_hugeLA() {
// doTestLookahead(500, 2500);
// }
//
// @Test public void test_avgFile_largeLA() {
// doTestLookahead(50, 25000);
// }
//
// @Test public void test_largeFile_largeLA() {
// doTestLookahead(50, 2500000);
// }
//
// @Test public void test_largeFile_tinyLA() {
// doTestLookahead(2, 2500000);
// }
//
// @Test public void test_largeFile_noLA() {
// doTestLookahead(1, 2500000);
// }
//
// protected void doTestLookahead(int lookAhead, int tokenCount) {
// this.tokenCount = tokenCount;
// XtextTokenStream stream = new XtextTokenStream(this, Token.DEFAULT_CHANNEL);
// while(stream.LA(1) != Token.EOF) {
// for(int i = 0; i < lookAhead; i++) {
// for(int j = i + 1; j < lookAhead; j++) {
// stream.LA(j - i);
// }
// stream.consume();
// }
// }
// }
@Test
public void test_smallFile_hugeLA() {
doTestLookahead(500, 2500);
}
@Test
public void test_avgFile_largeLA() {
doTestLookahead(50, 25000);
}
@Test
public void test_largeFile_largeLA() {
doTestLookahead(50, 2500000);
}
@Test
public void test_largeFile_tinyLA() {
doTestLookahead(2, 2500000);
}
@Test
public void test_largeFile_noLA() {
doTestLookahead(1, 2500000);
}
protected void doTestLookahead(int lookAhead, int tokenCount) {
this.tokenCount = tokenCount;
XtextTokenStream stream = new XtextTokenStream(this, Token.DEFAULT_CHANNEL);
while(stream.LA(1) != Token.EOF) {
for(int i = 0; i < lookAhead; i++) {
for(int j = i + 1; j < lookAhead; j++) {
stream.LA(j - i);
}
stream.consume();
}
}
}
public Token nextToken() {
if (tokenCount == 0)

View file

@ -9,10 +9,13 @@ package org.eclipse.xtext.parser.unorderedGroups;
import org.eclipse.xtext.parser.unorderedGroups.unorderedGroupsTestLanguage.Model;
import org.eclipse.xtext.parser.unorderedGroups.unorderedGroupsTestLanguage.UnorderedGroupsTestLanguageFactory;
import org.eclipse.xtext.parser.unorderedGroups.unorderedGroupsTestLanguage.UnorderedGroupsTestLanguagePackage;
import org.eclipse.xtext.parser.unorderedGroups.unorderedGroupsTestLanguage.UnorderedSerialization;
import org.eclipse.xtext.validation.AbstractConcreteSyntaxValidationTest;
import org.eclipse.xtext.validation.IConcreteSyntaxDiagnosticProvider;
import org.eclipse.xtext.validation.IConcreteSyntaxValidator;
import org.eclipse.xtext.validation.impl.ConcreteSyntaxValidator;
import org.junit.Ignore;
import org.junit.Test;
/**
@ -135,15 +138,17 @@ public class ConcreteSyntaxValidatorTest extends AbstractConcreteSyntaxValidatio
validate(toBeValidated).assertOK();
}
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=310454
// @Test public void testValidate_2_A_A_B() {
// toBeValidated.getFirstAsList().add("a");
// toBeValidated.getFirstAsList().add("a");
// toBeValidated.getSecondAsList().add("b");
// validate(toBeValidated).assertAll(
// err(pack.getUnorderedSerialization_FirstAsList(), ERROR_LIST_TOO_MANY, null, 1, "((first? second? third? forth?)|(firstAsList secondAsList)*|(firstAsList+ second)*)"),
// err(pack.getUnorderedSerialization_SecondAsList(), ERROR_LIST_TOO_FEW, 2, null, "((first? second? third? forth?)|(firstAsList secondAsList)*|(firstAsList+ second)*)"));
// }
@Test
@Ignore("see https://bugs.eclipse.org/bugs/show_bug.cgi?id=310454")
public void testValidate_2_A_A_B() {
UnorderedGroupsTestLanguagePackage pack = UnorderedGroupsTestLanguagePackage.eINSTANCE;
toBeValidated.getFirstAsList().add("a");
toBeValidated.getFirstAsList().add("a");
toBeValidated.getSecondAsList().add("b");
validate(toBeValidated).assertAll(
err(pack.getUnorderedSerialization_FirstAsList(), IConcreteSyntaxDiagnosticProvider.ERROR_LIST_TOO_MANY, null, 1, "((first? second? third? forth?)|(firstAsList secondAsList)*|(firstAsList+ second)*)"),
err(pack.getUnorderedSerialization_SecondAsList(), IConcreteSyntaxDiagnosticProvider.ERROR_LIST_TOO_FEW, 2, null, "((first? second? third? forth?)|(firstAsList secondAsList)*|(firstAsList+ second)*)"));
}
@Test public void testValidate_2_A_B_A_B() {
toBeValidated.getFirstAsList().add("a");

View file

@ -10,6 +10,7 @@ import org.eclipse.xtext.parsetree.reconstr.hiddentokenmergertest.Hiddentokenmer
import org.eclipse.xtext.parsetree.reconstr.hiddentokenmergertest.RefList;
import org.eclipse.xtext.parsetree.reconstr.hiddentokenmergertest.ValueList;
import org.eclipse.xtext.resource.SaveOptions;
import org.junit.Ignore;
import org.junit.Test;
public class HiddenTokensMergerTest extends AbstractXtextTests {
@ -87,10 +88,12 @@ public class HiddenTokensMergerTest extends AbstractXtextTests {
assertEquals("#5 a. b c.d e.f.g.i refs a./* ab */ b e. /*ef*/f.g/*hi*/.i c./*cd*/ d", serialize(model));
}
// @Test public void testRefList3() throws Exception {
// RefList model = (RefList) getResourceFromStringAndExpect("#5 a.b refs x.y", 1).getContents().get(0);
// assertEquals("#5 a. b c.d e.f.g.i refs a./* ab */ b e. /*ef*/f.g/*hi*/.i c./*cd*/ d", serialize(model));
// }
@Test
@Ignore
public void testRefList3() throws Exception {
RefList model = (RefList) getResourceFromStringAndExpect("#5 a.b refs x.y", 1).getContents().get(0);
assertEquals("#5 a. b c.d e.f.g.i refs a./* ab */ b e. /*ef*/f.g/*hi*/.i c./*cd*/ d", serialize(model));
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=297938
@Test public void testAppendToEnd() throws Exception {

View file

@ -2,6 +2,8 @@ package org.eclipse.xtext.parsetree.reconstr;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.junit4.AbstractXtextTests;
import org.eclipse.xtext.parser.IAstFactory;
import org.eclipse.xtext.parsetree.reconstr.complexrewritetest.ComplexrewritetestPackage;
import org.eclipse.xtext.resource.SaveOptions;
import org.junit.Test;
@ -20,38 +22,35 @@ public class WhitespacePreservingCallbackTest extends AbstractXtextTests {
check("a \t /* foo bar */ + b");
}
@Test
public void testFail1() throws Exception {
IAstFactory f = getASTFactory();
failsWith(f.create(ComplexrewritetestPackage.Literals.ADD), XtextSerializationException.class);
}
// FIXME: Make this test work again
@Test
public void testFail2() throws Exception {
IAstFactory f = getASTFactory();
EObject add = f.create(ComplexrewritetestPackage.Literals.ADD);
// @Test public void testFail1() throws Exception {
// IAstFactory f = getASTFactory();
// failsWith(f.create("Add"), XtextSerializationException.class);
// }
// one operand INVALID
EObject atom1 = f.create(ComplexrewritetestPackage.Literals.ATOM);
f.set(atom1, "name", "x", null, null);
f.add(add, "addOperands", atom1, null, null);
failsWith(add, XtextSerializationException.class);
// FIXME: Make this test work again
// two operands VALID
EObject atom2 = f.create(ComplexrewritetestPackage.Literals.ATOM);
f.set(atom2, "name", "x", null, null);
f.add(add, "addOperands", atom2, null, null);
assertNotNull(serialize(add));
// @Test public void testFail2() throws Exception {
// IAstFactory f = getASTFactory();
// EObject add = f.create("Add");
//
// // one operand INVALID
// EObject atom1 = f.create("Atom");
// f.set(atom1, "name", "x");
// f.add(add, "addOperands", atom1);
// failsWith(add, XtextSerializationException.class);
//
// // two operands VALID
// EObject atom2 = f.create("Atom");
// f.set(atom2, "name", "x");
// f.add(add, "addOperands", atom2);
// assertNotNull(serialize(add));
//
// // three operands INVALID
// EObject atom3 = f.create("Atom");
// f.set(atom3, "name", "x");
// f.add(add, "addOperands", atom3);
// failsWith(add, XtextSerializationException.class);
// }
// three operands INVALID
EObject atom3 = f.create(ComplexrewritetestPackage.Literals.ATOM);
f.set(atom3, "name", "x", null, null);
f.add(add, "addOperands", atom3, null, null);
failsWith(add, XtextSerializationException.class);
}
private void check(String m1) throws Exception {
assertEquals(m1, parseAndSerialize(m1));
@ -62,7 +61,6 @@ public class WhitespacePreservingCallbackTest extends AbstractXtextTests {
return getSerializer().serialize(result, SaveOptions.defaultOptions());
}
@SuppressWarnings("unused")
private void failsWith(EObject o, Class<? extends RuntimeException> clazz) {
try {
get(Serializer.class).serialize(o);

View file

@ -14,6 +14,7 @@ import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic;
import org.eclipse.xtext.serializer.sequencer.ISemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.NodeModelSemanticSequencer;
import org.eclipse.xtext.serializer.serializer.AbstractSequencerTestLanguageSemanticSequencer;
import org.junit.Ignore;
import org.junit.Test;
import com.google.inject.Inject;
@ -79,24 +80,26 @@ public abstract class AbstractSemanticSequencerTest extends AbstractXtextTests {
assertEquals(expected.toString(), generatedActual.toString());
}
// @Test public void testXtext() throws Exception {
// with(XtextStandaloneSetup.class);
// EObject model = getGrammarAccess().getGrammar();
// // System.out.println(EmfFormatter.objToStr(model));
// EObject ctx = GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "AbstractToken");
// // ISemanticSequencer semSequencer = get(ISemanticSequencer.class);
// // EObject ctx = semSequencer.findContexts(model, null).iterator().next();
// ISyntacticSequencer synSeq = get(PassThroughSyntacticSequencer.class);
// IHiddenTokenSequencer hiddenSeq = get(PassThroughHiddenTokenSequencer.class);
// IRecursiveSequencer recSequencer = get(IRecursiveSequencer.class);
// ((IHiddenTokenSequencerOwner) recSequencer).setHiddenTokenSequencer(hiddenSeq);
// ((ISyntacticSequencerOwner) hiddenSeq).setSyntacticSequencer(synSeq);
// DebugSequenceAcceptor actual = new DebugSequenceAcceptor();
// recSequencer.createSequence( /* semSequencer, */ctx, model, actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
// // String actual = sequenceRecursively(semSequencer, ctx, model, true);
// // System.out.println(actual);
// assertNotNull(actual);
// }
@Test
@Ignore
public void testXtext() throws Exception {
// with(XtextStandaloneSetup.class);
// EObject model = getGrammarAccess().getGrammar();
// // System.out.println(EmfFormatter.objToStr(model));
// EObject ctx = GrammarUtil.findRuleForName(getGrammarAccess().getGrammar(), "AbstractToken");
// // ISemanticSequencer semSequencer = get(ISemanticSequencer.class);
// // EObject ctx = semSequencer.findContexts(model, null).iterator().next();
// ISyntacticSequencer synSeq = get(PassThroughSyntacticSequencer.class);
// IHiddenTokenSequencer hiddenSeq = get(PassThroughHiddenTokenSequencer.class);
// IRecursiveSequencer recSequencer = get(IRecursiveSequencer.class);
// ((IHiddenTokenSequencerOwner) recSequencer).setHiddenTokenSequencer(hiddenSeq);
// ((ISyntacticSequencerOwner) hiddenSeq).setSyntacticSequencer(synSeq);
// DebugSequenceAcceptor actual = new DebugSequenceAcceptor();
// recSequencer.createSequence( /* semSequencer, */ctx, model, actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
// // String actual = sequenceRecursively(semSequencer, ctx, model, true);
// // System.out.println(actual);
// assertNotNull(actual);
}
@Test public void testSimpleGroup() throws Exception {
testSequence("#1 a b");
@ -250,19 +253,23 @@ public abstract class AbstractSemanticSequencerTest extends AbstractXtextTests {
testSequence("#15 kw3");
}
// TODO: test multiple keywords
@Test
@Ignore("TODO: test multiple keywords")
public void testList3a() throws Exception {
testSequence("#8 a, b, c");
}
// @Test public void testList3a() throws Exception {
// testSequence("#8 a, b, c");
// }
//
// @Test public void testList3b() throws Exception {
// testSequence("#8 a");
// }
//
// @Test public void testList3c() throws Exception {
// testSequence("#8 kw3 a");
// }
@Test
@Ignore("TODO: test multiple keywords")
public void testList3b() throws Exception {
testSequence("#8 a");
}
@Test
@Ignore("TODO: test multiple keywords")
public void testList3c() throws Exception {
testSequence("#8 kw3 a");
}
@Test public void testDependentAlternative1_a() throws Exception {
testSequence("#19 foo1");

View file

@ -16,6 +16,7 @@ import org.eclipse.xtext.junit4.AbstractXtextTests;
import org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider;
import org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint;
import org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraintContext;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.base.Joiner;
@ -339,15 +340,19 @@ public class GrammarConstraintProviderTest extends AbstractXtextTests {
assertEquals(expected.toString(), actual);
}
// @Test public void testReturnsNullAlways() throws Exception {
// String actual = getParserRule("Rule: val1=NullRule val2=ID; NullRule: 'kw1';");
// StringBuilder expected = new StringBuilder();
// assertEquals(expected.toString(), actual);
// }
//
// @Test public void testReturnsNullSometimes() throws Exception {
// String actual = getParserRule("Rule: val1=NullRule val2=ID; NullRule: 'kw1' | 'kw2' {NullRule};");
// StringBuilder expected = new StringBuilder();
// assertEquals(expected.toString(), actual);
// }
@Test
@Ignore
public void testReturnsNullAlways() throws Exception {
String actual = getParserRule("Rule: val1=NullRule val2=ID; NullRule: 'kw1';");
StringBuilder expected = new StringBuilder();
assertEquals(expected.toString(), actual);
}
@Test
@Ignore
public void testReturnsNullSometimes() throws Exception {
String actual = getParserRule("Rule: val1=NullRule val2=ID; NullRule: 'kw1' | 'kw2' {NullRule};");
StringBuilder expected = new StringBuilder();
assertEquals(expected.toString(), actual);
}
}

View file

@ -28,6 +28,7 @@ import org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer;
import org.eclipse.xtext.serializer.sequencer.ISemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer;
import org.eclipse.xtext.serializer.sequencer.NodeModelSemanticSequencer;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.base.Joiner;
@ -107,18 +108,20 @@ public class HiddenTokenSequencerTest extends AbstractXtextTests {
assertEquals(Joiner.on("\n").join(getNodeSequence(model)), Joiner.on("\n").join(actual.getColumn(4)));
}
// @Test public void testXtext() throws Exception {
// with(XtextStandaloneSetup.class);
// Grammar model = (Grammar) new XtextResourceSet()
// .getResource(URI.createURI("classpath:/org/eclipse/xtext/Xtext.xtext"), true).getContents().get(0);
// IRecursiveSequencer recSequencer = get(IRecursiveSequencer.class);
// DebugSequenceAcceptor actual = new NoEnterNodesDebugSequenceAcceptor(false);
// recSequencer.createSequence(/*syn, semSequencer,*/getGrammarAccess().getGrammar().getRules().get(0), model,
// actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
// // System.out.println(actual);
// // System.out.println(NodeModelUtils.compactDump(NodeModelUtils.getNode(model), false));
// assertEquals(Join.join("\n", getNodeSequence(model)), Join.join("\n", actual.getColumn(4)));
// }
@Test
@Ignore
public void testXtext() throws Exception {
// with(XtextStandaloneSetup.class);
// Grammar model = (Grammar) new XtextResourceSet()
// .getResource(URI.createURI("classpath:/org/eclipse/xtext/Xtext.xtext"), true).getContents().get(0);
// IRecursiveSequencer recSequencer = get(IRecursiveSequencer.class);
// DebugSequenceAcceptor actual = new NoEnterNodesDebugSequenceAcceptor(false);
// recSequencer.createSequence(/*syn, semSequencer,*/getGrammarAccess().getGrammar().getRules().get(0), model,
// actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
// // System.out.println(actual);
// // System.out.println(NodeModelUtils.compactDump(NodeModelUtils.getNode(model), false));
// assertEquals(Joiner.on("\n").join(getNodeSequence(model)), Joiner.on("\n").join(actual.getColumn(4)));
}
@Test public void testMandatoryKeywords() throws Exception {
testSequence("#1 a kw1 b kw2 kw3 c kw4");

View file

@ -12,6 +12,7 @@ import java.util.Iterator;
import java.util.List;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.collect.Lists;
@ -92,21 +93,24 @@ public class PdaUtilTest extends Assert {
assertEquals("[A, B, C, C, C, D]", util.shortestStackpruningPathTo(pda, newStack("Y", "Y"), "D"));
}
// @Test public void testShortestStackemptyingSingleState() {
// PDA pda = newPDA();
// pda.state("A").start().stop();
// assertEquals("[A]", util.shortestStackpruningPathTo(pda, newStack(), "A"));
// }
@Test
@Ignore
public void testShortestStackemptyingSingleState() {
StringPda pda = new StringPda("A", "A");
pda.state("A");
assertEquals("[A]", util.shortestStackpruningPathTo(pda, newStack(), "A"));
}
// @Test public void testShortestStackemptyingPathLoops1() {
// PDA pda = newPDA();
// pda.state("A").start().followedBy("B");
// pda.state("B").followedBy("C").pop("X");
// pda.state("C").followedBy("D", "C").pop("Y");
// pda.state("D").stop();
// assertEquals("[A, B, C, D]", util.shortestStackpruningPathTo(pda, newStack(), "D"));
// assertEquals("[A, B, C, C, D]", util.shortestStackpruningPathTo(pda, newStack("Y"), "D"));
// assertEquals("[A, B, C, C, C, D]", util.shortestStackpruningPathTo(pda, newStack("Y", "Y"), "D"));
// }
@Test
@Ignore
public void testShortestStackemptyingPathLoops1() {
StringPda pda = new StringPda("A", "D");
pda.state("A").followedBy("B");
pda.state("B").followedBy("C").pop("X");
pda.state("C").followedBy("D", "C").pop("Y");
assertEquals("[A, B, C, D]", util.shortestStackpruningPathTo(pda, newStack(), "D"));
assertEquals("[A, B, C, C, D]", util.shortestStackpruningPathTo(pda, newStack("Y"), "D"));
assertEquals("[A, B, C, C, C, D]", util.shortestStackpruningPathTo(pda, newStack("Y", "Y"), "D"));
}
}

View file

@ -10,6 +10,8 @@ package org.eclipse.xtext.validation;
import static org.eclipse.xtext.junit4.validation.AssertableDiagnostics.*;
import static org.eclipse.xtext.validation.IConcreteSyntaxDiagnosticProvider.*;
import java.util.List;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
@ -25,6 +27,7 @@ import org.eclipse.xtext.validation.csvalidationtest.Combination4;
import org.eclipse.xtext.validation.csvalidationtest.CsvalidationtestFactory;
import org.eclipse.xtext.validation.csvalidationtest.CsvalidationtestPackage;
import org.eclipse.xtext.validation.csvalidationtest.GroupMultiplicities;
import org.eclipse.xtext.validation.csvalidationtest.Heuristic1;
import org.eclipse.xtext.validation.csvalidationtest.List1;
import org.eclipse.xtext.validation.csvalidationtest.List2;
import org.eclipse.xtext.validation.csvalidationtest.List3;
@ -48,8 +51,11 @@ import org.eclipse.xtext.validation.csvalidationtest.UnassignedRuleCall2Sub;
import org.eclipse.xtext.validation.csvalidationtest.UnassignedRuleCall2SubAction;
import org.eclipse.xtext.validation.csvalidationtest.impl.TransientObjectImpl;
import org.eclipse.xtext.validation.impl.ConcreteSyntaxValidator;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.collect.Lists;
/**
* @author meysholdt - Initial contribution and API
*/
@ -641,68 +647,70 @@ public class ConcreteSyntaxValidationTest extends AbstractConcreteSyntaxValidati
"((shared1? shared2 shared3* version1?)|((extra2 extra3)|extra4)?)"));
}
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=310454
// private List<String> strings(int count) {
// List<String> result = Lists.newArrayList();
// for (int i = 0; i < count; i++)
// result.add("foo" + i);
// return result;
// }
//
// @Test public void testHeuristic1() {
// Heuristic1 m = f.createHeuristic1();
// m.getA().addAll(Lists.newArrayList("foo", "foo", "foo"));
// m.getB().addAll(Lists.newArrayList("foo", "foo", "foo"));
// validate(m).assertOK();
//
// m = f.createHeuristic1();
// m.getA().addAll(Lists.newArrayList("foo", "foo", "foo"));
// m.getC().addAll(Lists.newArrayList("foo", "foo", "foo"));
// validate(m).assertOK();
//
// m = f.createHeuristic1();
// m.getB().addAll(Lists.newArrayList("foo", "foo", "foo"));
// m.getC().addAll(Lists.newArrayList("foo", "foo", "foo"));
// validate(m).assertOK();
//
// m = f.createHeuristic1();
// m.getA().addAll(Lists.newArrayList("foo", "foo", "foo"));
// m.getB().addAll(Lists.newArrayList("foo", "foo", "foo"));
// m.getB().addAll(Lists.newArrayList("foo", "foo"));
// m.getC().addAll(Lists.newArrayList("foo", "foo"));
// validate(m).assertOK();
//
// m = f.createHeuristic1();
// m.getA().addAll(Lists.newArrayList("foo", "foo", "foo"));
// m.getB().addAll(Lists.newArrayList("foo", "foo", "foo"));
// m.getB().addAll(Lists.newArrayList("foo", "foo"));
// m.getC().addAll(Lists.newArrayList("foo", "foo"));
// m.getA().addAll(Lists.newArrayList("foo"));
// m.getC().addAll(Lists.newArrayList("foo"));
// validate(m).assertOK();
//
// }
//
// @Test public void testHeuristic1Large1() {
// Heuristic1 m = f.createHeuristic1();
// m.getA().addAll(strings(42));
// m.getB().addAll(strings(42));
// m.getB().addAll(strings(37));
// m.getC().addAll(strings(37));
// m.getA().addAll(strings(111));
// m.getC().addAll(strings(111));
// validate(m).assertOK();
// }
//
// @Test public void testHeuristic1Large2() {
// Heuristic1 m = f.createHeuristic1();
// m.getA().addAll(strings(42));
// m.getB().addAll(strings(42));
// m.getB().addAll(strings(37));
// m.getC().addAll(strings(37));
// m.getA().addAll(strings(111));
// m.getC().addAll(strings(111));
// m.getC().addAll(Lists.newArrayList("foo"));
// validate(m).assertAll(errorCode(ERROR_LIST_TOO_MANY), errorCode(ERROR_LIST_TOO_FEW));
// }
private List<String> strings(int count) {
List<String> result = Lists.newArrayList();
for (int i = 0; i < count; i++)
result.add("foo" + i);
return result;
}
@Test
public void testHeuristic1() {
Heuristic1 m = f.createHeuristic1();
m.getA().addAll(Lists.newArrayList("foo", "foo", "foo"));
m.getB().addAll(Lists.newArrayList("foo", "foo", "foo"));
validate(m).assertOK();
m = f.createHeuristic1();
m.getA().addAll(Lists.newArrayList("foo", "foo", "foo"));
m.getC().addAll(Lists.newArrayList("foo", "foo", "foo"));
validate(m).assertOK();
m = f.createHeuristic1();
m.getB().addAll(Lists.newArrayList("foo", "foo", "foo"));
m.getC().addAll(Lists.newArrayList("foo", "foo", "foo"));
validate(m).assertOK();
m = f.createHeuristic1();
m.getA().addAll(Lists.newArrayList("foo", "foo", "foo"));
m.getB().addAll(Lists.newArrayList("foo", "foo", "foo"));
m.getB().addAll(Lists.newArrayList("foo", "foo"));
m.getC().addAll(Lists.newArrayList("foo", "foo"));
validate(m).assertOK();
m = f.createHeuristic1();
m.getA().addAll(Lists.newArrayList("foo", "foo", "foo"));
m.getB().addAll(Lists.newArrayList("foo", "foo", "foo"));
m.getB().addAll(Lists.newArrayList("foo", "foo"));
m.getC().addAll(Lists.newArrayList("foo", "foo"));
m.getA().addAll(Lists.newArrayList("foo"));
m.getC().addAll(Lists.newArrayList("foo"));
validate(m).assertOK();
}
@Test
public void testHeuristic1Large1() {
Heuristic1 m = f.createHeuristic1();
m.getA().addAll(strings(42));
m.getB().addAll(strings(42));
m.getB().addAll(strings(37));
m.getC().addAll(strings(37));
m.getA().addAll(strings(111));
m.getC().addAll(strings(111));
validate(m).assertOK();
}
@Test
@Ignore("see https://bugs.eclipse.org/bugs/show_bug.cgi?id=310454")
public void testHeuristic1Large2() {
Heuristic1 m = f.createHeuristic1();
m.getA().addAll(strings(42));
m.getB().addAll(strings(42));
m.getB().addAll(strings(37));
m.getC().addAll(strings(37));
m.getA().addAll(strings(111));
m.getC().addAll(strings(111));
m.getC().addAll(Lists.newArrayList("foo"));
validate(m).assertAll(errorCode(ERROR_LIST_TOO_MANY), errorCode(ERROR_LIST_TOO_FEW));
}
}

View file

@ -15,9 +15,11 @@ import java.util.Set;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreValidator;
import org.eclipse.xtext.AbstractMetamodelDeclaration;
@ -40,8 +42,10 @@ import org.eclipse.xtext.UnorderedGroup;
import org.eclipse.xtext.XtextFactory;
import org.eclipse.xtext.XtextStandaloneSetup;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.util.StringInputStream;
import org.eclipse.xtext.validation.AbstractValidationMessageAcceptingTestCase;
import org.eclipse.xtext.validation.AbstractValidationMessageAcceptor;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.base.Predicate;
@ -95,29 +99,61 @@ public class XtextValidationTest extends AbstractValidationMessageAcceptingTestC
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
// @Test public void testBug322875_01() throws Exception {
// String testGrammar = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
// " import 'classpath:/org/eclipse/xtext/xtext/XtextValidationTest.ecore' " +
// " import 'http://www.eclipse.org/2008/Xtext' as xtext\n" +
// "Bug322875 returns Bug322875: referencesETypeFromClasspathPackage=[xtext::Grammar];";
// XtextResource resource = getResourceFromStringAndExpect(testGrammar,1);
// assertFalse(resource.getErrors().toString(), resource.getErrors().isEmpty());
// Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
// assertNotNull("diag", diag);
// assertEquals(diag.toString(), 1, diag.getChildren().size());
// assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
// }
@Test
public void testBug322875_01() throws Exception {
String testGrammar = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
" import 'classpath:/org/eclipse/xtext/xtext/XtextValidationTest.ecore' " +
" import 'http://www.eclipse.org/2008/Xtext' as xtext\n" +
"Bug322875 returns Bug322875: referencesETypeFromClasspathPackage=[xtext::Grammar];";
XtextResource resource = getResourceFromStringAndExpect(testGrammar,1);
assertFalse(resource.getErrors().toString(), resource.getErrors().isEmpty());
assertBug322875(resource);
}
protected void assertBug322875(XtextResource resource) {
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
assertNotNull("diag", diag);
assertEquals(diag.toString(), 0, diag.getChildren().size());
assertEquals("diag.isOk", Diagnostic.OK, diag.getSeverity());
int xtextPackageCounter = 0;
int validationTestCounter = 0;
for(Resource packResource: resource.getResourceSet().getResources()) {
EObject object = packResource.getContents().get(0);
if (object instanceof EPackage) {
String nsURI = ((EPackage) object).getNsURI();
if (nsURI.equals("http://www.eclipse.org/2008/Xtext"))
xtextPackageCounter++;
if (nsURI.equals("http://XtextValidationBugs")) {
validationTestCounter++;
}
}
}
assertEquals(1, xtextPackageCounter);
assertEquals(1, validationTestCounter);
}
// @Test public void testBug322875_02() throws Exception {
// String testGrammar = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
// " import 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore' " +
// "Model returns EClass: name=ID;";
// XtextResource resource = getResourceFromString(testGrammar);
// Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
// assertNotNull("diag", diag);
// assertEquals(diag.toString(), 1, diag.getChildren().size());
// assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
// }
@Test
public void testBug322875_01_b() throws Exception {
String testGrammar = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
" import 'http://www.eclipse.org/2008/Xtext' as xtext\n" +
" import 'classpath:/org/eclipse/xtext/xtext/XtextValidationTest.ecore' " +
"Bug322875 returns Bug322875: referencesETypeFromClasspathPackage=[xtext::Grammar];";
XtextResource resource = getResourceFromStringAndExpect(testGrammar,1);
assertFalse(resource.getErrors().toString(), resource.getErrors().isEmpty());
assertBug322875(resource);
}
@Test
public void testBug322875_02() throws Exception {
String testGrammar = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
" import 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore' " +
"Model returns EClass: name=ID;";
XtextResource resource = getResourceFromString(testGrammar);
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
assertNotNull("diag", diag);
assertEquals(diag.toString(), 0, diag.getChildren().size());
assertEquals("diag.isOk", Diagnostic.OK, diag.getSeverity());
}
@Test public void testBug322875_03() throws Exception {
String testGrammar = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
@ -129,24 +165,24 @@ public class XtextValidationTest extends AbstractValidationMessageAcceptingTestC
assertEquals(diag.toString(), 0, diag.getChildren().size());
}
// @Test public void testBug322875_04() throws Exception {
// String testGrammarOk = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
// " import 'http://www.eclipse.org/emf/2002/Ecore' " +
// "Model returns EClass: name=ID;";
// String testGrammarWithError = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
// " import 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore' " +
// "Model returns EClass: name=ID;";
// XtextResource resourceOk = getResourceFromString(testGrammarOk);
// XtextResource resourceError = (XtextResource) resourceOk.getResourceSet().createResource(URI.createURI("unused.xtext"));
// resourceError.load(new StringInputStream(testGrammarWithError), null);
// Diagnostic diagOK = Diagnostician.INSTANCE.validate(resourceOk.getContents().get(0));
// assertNotNull("diag", diagOK);
// assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
// Diagnostic diagError = Diagnostician.INSTANCE.validate(resourceError.getContents().get(0));
// assertNotNull("diag", diagError);
// assertEquals(diagError.toString(), 1, diagError.getChildren().size());
// assertEquals("diag.isError", diagError.getSeverity(), Diagnostic.ERROR);
// }
@Test
public void testBug322875_04() throws Exception {
String testGrammarNsURI = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
" import 'http://www.eclipse.org/emf/2002/Ecore' " +
"Model returns EClass: name=ID;";
String testGrammarPlatformPlugin = "grammar foo.Bar with org.eclipse.xtext.common.Terminals\n " +
" import 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore' " +
"Model returns EClass: name=ID;";
XtextResource resourceOk = getResourceFromString(testGrammarNsURI);
XtextResource resourceOk2 = (XtextResource) resourceOk.getResourceSet().createResource(URI.createURI("unused.xtext"));
resourceOk2.load(new StringInputStream(testGrammarPlatformPlugin), null);
Diagnostic diagOK = Diagnostician.INSTANCE.validate(resourceOk.getContents().get(0));
assertNotNull("diag", diagOK);
assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
diagOK = Diagnostician.INSTANCE.validate(resourceOk2.getContents().get(0));
assertNotNull("diag", diagOK);
assertEquals(diagOK.toString(), 0, diagOK.getChildren().size());
}
@Test public void testBug_282852_01() throws Exception {
XtextResource resource = getResourceFromString(
@ -491,20 +527,21 @@ public class XtextValidationTest extends AbstractValidationMessageAcceptingTestC
assertTrue(diag.getChildren().toString(), diag.getChildren().isEmpty());
}
//TODO this one should yield a warning, because two different instances of a package might be referenced.
// @Test public void testBug_280413_03() throws Exception {
// XtextResource resource = getResourceFromString(
// "grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
// "import 'classpath:/org/eclipse/xtext/Xtext.ecore' as xtext\n" +
// "ParserRule returns xtext::ParserRule: name = ID;");
// assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
// assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
//
// Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
// assertNotNull("diag", diag);
// assertEquals(diag.getSeverity(), Diagnostic.OK);
// assertTrue(diag.getChildren().toString(), diag.getChildren().isEmpty());
// }
@Test
@Ignore("TODO this one should yield a warning, because two different instances of a package (ecore itself) might be referenced.")
public void testBug_280413_03() throws Exception {
XtextResource resource = getResourceFromString(
"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
"import 'classpath:/org/eclipse/xtext/Xtext.ecore' as xtext\n" +
"ParserRule returns xtext::ParserRule: name = ID;");
assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
assertNotNull("diag", diag);
assertEquals(diag.getSeverity(), Diagnostic.OK);
assertTrue(diag.getChildren().toString(), diag.getChildren().isEmpty());
}
@Test public void testBug_281660() throws Exception {
XtextResource resource = getResourceFromStringAndExpect(