This commit is contained in:
sefftinge 2008-10-08 12:13:54 +00:00 committed by sefftinge
parent 713f305781
commit a6128c3666
4 changed files with 47 additions and 24 deletions

View file

@ -8,6 +8,8 @@
*******************************************************************************/
package org.eclipse.xtext.parsetree.reconstr;
import java.io.ByteArrayOutputStream;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
@ -55,10 +57,11 @@ public class ComplexReconstrTest extends AbstractGeneratorTest {
EObject result = (EObject) getModel(model);
System.out.println(EmfFormater.objToStr(result, ""));
IParseTreeConstructor con = getParseTreeConstructor();
WhitespacePreservingCallback callback = new WhitespacePreservingCallback(
ByteArrayOutputStream out = new ByteArrayOutputStream();
WhitespacePreservingCallback callback = new WhitespacePreservingCallback(out,
getValueConverterService());
con.update(result, callback);
return callback.toString();
return out.toString();
}
public void testNormalizableCompositeNodesIncluded() throws Exception {

View file

@ -8,7 +8,10 @@
*******************************************************************************/
package org.eclipse.xtext.parsetree.reconstr;
import java.io.ByteArrayOutputStream;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.parsetree.reconstr.callbacks.WhitespacePreservingCallback;
import org.eclipse.xtext.testlanguages.SimpleExpressionsStandaloneSetup;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
@ -25,29 +28,31 @@ public class SimpleReconstrTest extends AbstractGeneratorTest {
String model = "( a b ) !";
assertEquals(model, parseAndSerialize(model));
}
// FIXME: make this work again
// public void testFollowingHiddenTokens() throws Exception {
// String model = "a ";
// assertEquals(model, parseAndSerialize(model));
// }
public void testFollowingHiddenTokens() throws Exception {
String model = "a ";
assertEquals(model, parseAndSerialize(model));
}
// FIXME: make this work again
// public void testComplex() throws Exception {
// String model = "( ( a b ) ! c d e f ( x s ) ( \t ( a \n\rb/*ffo \n bar */ ) ! c ) ! ) //holla\n!";
// assertEquals(model, parseAndSerialize(model));
// }
public void testComplex() throws Exception {
String model = "( ( a b ) ! c d e f ( x s ) ( \t ( a \n\rb/*ffo \n bar */ ) ! c ) ! ) //holla\n!";
assertEquals(model, parseAndSerialize(model));
}
private String parseAndSerialize(String model) throws Exception {
EObject result = (EObject) getModel(model);
System.out.println(EmfFormater.objToStr(result, ""));
System.out.println(EmfFormater.objToStr(NodeUtil.getRootNode(result),
""));
System.out.println(EmfFormater.objToStr(NodeUtil.getRootNode(result)
.getLeafNodes(), ""));
IParseTreeConstructor con = getParseTreeConstructor();
WhitespacePreservingCallback callback = new WhitespacePreservingCallback(
ByteArrayOutputStream out = new ByteArrayOutputStream();
WhitespacePreservingCallback callback = new WhitespacePreservingCallback(out,
getValueConverterService());
con.update(result, callback);
return callback.toString();
return out.toString();
}
public void testSimpleExpressions5() throws Exception {

View file

@ -1,6 +1,9 @@
package org.eclipse.xtext.parsetree.reconstr;
import java.io.ByteArrayOutputStream;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parser.IAstFactory;
import org.eclipse.xtext.parsetree.reconstr.callbacks.WhitespacePreservingCallback;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
@ -15,11 +18,9 @@ public class WhitespacePreservingCallbackTest extends AbstractGeneratorTest {
check("a");
}
// FIXME: Make this test work again
// public void testHiddenInBetween() throws Exception {
// check("a \t /* foo bar */ + b");
// }
public void testHiddenInBetween() throws Exception {
check("a \t /* foo bar */ + b");
}
// FIXME: Make this test work again
@ -65,15 +66,17 @@ public class WhitespacePreservingCallbackTest extends AbstractGeneratorTest {
private String serialize(EObject result) {
IParseTreeConstructor con = getParseTreeConstructor();
WhitespacePreservingCallback cb = new WhitespacePreservingCallback(getValueConverterService());
ByteArrayOutputStream out = new ByteArrayOutputStream();
WhitespacePreservingCallback cb = new WhitespacePreservingCallback(out,getValueConverterService());
con.update(result, cb);
return cb.toString();
return out.toString();
}
private void failsWith(EObject o, Class<? extends RuntimeException> clazz) {
try {
IParseTreeConstructor con = getParseTreeConstructor();
WhitespacePreservingCallback cb = new WhitespacePreservingCallback(getValueConverterService());
ByteArrayOutputStream out = new ByteArrayOutputStream();
WhitespacePreservingCallback cb = new WhitespacePreservingCallback(out,getValueConverterService());
con.update(o, cb);
fail("Should fail with "+clazz.getSimpleName());
} catch (RuntimeException e) {

View file

@ -27,6 +27,7 @@ import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.XtextStandaloneSetup;
import org.eclipse.xtext.resource.metamodel.ErrorAcceptor.ErrorCode;
import org.eclipse.xtext.tests.AbstractGeneratorTest;
import org.eclipse.xtext.util.EmfFormater;
/**
* @author Jan Köhnlein - Initial contribution and API
@ -688,4 +689,15 @@ public class Xtext2EcoreTransformerTests extends AbstractGeneratorTest {
assertSame(ruleB, ruleC.getESuperTypes().get(0));
assertEquals(0, ruleD.getESuperTypes().size());
}
public void testExpressionLikeLangauge() throws Exception {
String grammar = "language test generate test 'http://test'";
grammar += " Ex : Atom ({ChainExpression.left+=current} operator=('+'|'-'|'*'|'/') right=Atom )*;" +
"Atom returns Ex : Number | '(' Ex ')';" +
"Number : value=INT";
EPackage ePackage = getEPackageFromGrammar(grammar);
EClass classifier = (EClass) ePackage.getEClassifier("Ex");
System.out.println(EmfFormater.objToStr(ePackage, ""));
assertEquals(0,classifier.getEStructuralFeatures().size());
}
}