use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTest method testResourceURIChange.
@Test
public void testResourceURIChange() {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/f.pstl", "#1 root { }"));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
Node model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/f.pstl", Node.class);
IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
serializer.addModification(model.eResource(), (Resource it) -> {
model.eResource().setURI(URI.createURI("inmemory:/x.pstl"));
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "----- renamed inmemory:/f.pstl to inmemory:/x.pstl (syntax: <offset|text>) -----\n" + "(no changes)\n" + "--------------------------------------------------------------------------------\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTest method testRenameLocal.
@Test
public void testRenameLocal() {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#1 root { foo1; foo2 { ref foo1 } }"));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
Node model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", Node.class);
IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
serializer.addModification(model.eResource(), (Resource it) -> {
model.getChildren().get(0).setName("bazz4");
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root { <10:4|bazz4>; foo2 { ref <27:4|bazz4> } }\n" + "--------------------------------------------------------------------------------\n" + "10 4 \"foo1\" -> \"bazz4\"\n" + "27 4 \"foo1\" -> \"bazz4\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerWithEmfTest method testChangeInDSL.
@Test
public void testChangeInDSL() {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#20 DslEClass"));
String ecore = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">\n" + " <eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\" eSuperTypes=\"inmemory:/file1.pstl#//@clazz.0\"/>\n" + "</ecore:EPackage>\n";
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file2.ecore", ecore));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
Model model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", Model.class);
ChangeSerializer serializer = serializerProvider.get();
serializer.addModification(model.eResource(), (Resource it) -> {
model.getClazz().get(0).setName("ChangedName");
EClass newEClass = EcoreFactory.eINSTANCE.createEClass();
newEClass.setName("NewName");
model.getClazz().add(0, newEClass);
Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#20 <4:0|NewName ><4:9| ChangedName>\n" + "--------------------------------------------------------------------------------\n" + "4 0 \"\" -> \"NewName \"\n" + "4 9 \"DslEClass\" -> \" ChangedName\"\n" + "---------------------------- inmemory:/file2.ecore -----------------------------\n" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">\n" + " <eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\" eSuperTypes=\"file1.pstl#//@clazz.1\"/>\n" + "</ecore:EPackage>\n" + "--------------------------------------------------------------------------------\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerWithImports method testRenameGlobal1.
@Test
public void testRenameGlobal1() {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#1 root1 { child1; }"));
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file2.pstl", "#1 import root1.child1 refs child1;"));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
Node model = changeSerializerTestHelper.<Node>findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", Node.class);
ChangeSerializer serializer = serializerProvider.get();
serializer.addModification(model.eResource(), (Resource it) -> {
model.getChildren().get(0).setName("newchild");
Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root1 { <11:6|newchild>; }\n" + "--------------------------------------------------------------------------------\n" + "11 6 \"child1\" -> \"newchild\"\n" + "----------------- inmemory:/file2.pstl (syntax: <offset|text>) -----------------\n" + "#1 import <10:12|root1.newchild> refs <28:6|newchild>;\n" + "--------------------------------------------------------------------------------\n" + "10 12 \"root1.child1\" -> \"root1.newchild\"\n" + "28 6 \"child1\" -> \"newchild\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class PartialSerializerTest method recordDiff.
private <T extends EObject> ITextRegionAccess recordDiff(Class<T> modelType, String modelText, IChangeSerializer.IModification<T> modification) {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", modelText));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
T model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", modelType);
ChangeSerializer serializer = serializerProvider.get();
serializer.addModification(model, modification);
return changeSerializerTestHelper.endRecordChangesToTextRegions(serializer);
}
Aggregations