use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTest method testMoveElement_2a.
@Test
public void testMoveElement_2a() {
InMemoryURIHandler fs = new InMemoryURIHandler();
String content = "#22 {\n" + " child1 child3\n" + " children1 {\n" + " child2 jumper\n" + " }\n" + "}";
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file-move2a.pstl", content));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
TwoChildLists model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file-move2a.pstl", TwoChildLists.class);
IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
serializer.addModification(model.eResource(), (Resource it) -> {
model.getDirectChildren().add(1, IterableExtensions.findFirst(model.getChildsList().getChildren(), (MandatoryValue v) -> "jumper".equals(v.getName())));
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "-------------- inmemory:/file-move2a.pstl (syntax: <offset|text>) --------------\n" + "#22 {\n" + " child1 <14:0|jumper >child3\n" + " children1 {\n" + " child2 <43:6|>\n" + " }\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "14 0 \"\" -> \"jumper \"\n" + "43 6 \"jumper\" -> \"\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTest method testMoveElement_3.
@Test
public void testMoveElement_3() {
InMemoryURIHandler fs = new InMemoryURIHandler();
String content = "#24 direct:\n" + " child:jumper\n";
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file-move3.pstl", content));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
TwoChilds model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file-move3.pstl", TwoChilds.class);
IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
serializer.addModification(model.eResource(), (Resource it) -> {
model.setDirectChild(model.getOptChild().getChild());
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "-------------- inmemory:/file-move3.pstl (syntax: <offset|text>) ---------------\n" + "<0:26|#24 direct:\n" + " jumper\n" + "child :>\n" + "--------------------------------------------------------------------------------\n" + "0 26 \"#24 direct:\\n" + " chil...\" -> \"#24 direct:\\n" + " jump...\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTest method testRenameGlobal1.
@Test
public void testRenameGlobal1() {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#1 root1;"));
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file2.pstl", "#1 root2 { ref root1 }"));
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.setName("newroot");
});
Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 <3:5|newroot>;\n" + "--------------------------------------------------------------------------------\n" + "3 5 \"root1\" -> \"newroot\"\n" + "----------------- inmemory:/file2.pstl (syntax: <offset|text>) -----------------\n" + "#1 root2 { ref <15:5|newroot> }\n" + "--------------------------------------------------------------------------------\n" + "15 5 \"root1\" -> \"newroot\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerWithEmfTest method testChangeRefToXML.
@Test
public void testChangeRefToXML() {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#21 MyPackage.MyClass1"));
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=\"#//MyClass2\"/>\n" + " <eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass2\"/>\n" + "</ecore:EPackage>\n";
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file2.ecore", ecore));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
EClassRef model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", EClassRef.class);
ChangeSerializer serializer = serializerProvider.get();
serializer.addModification(model, (EClassRef it) -> {
model.setRef(((EClass) model.getRef().getEPackage().getEClassifiers().get(1)));
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#21 <4:18|MyPackage.MyClass2>\n" + "--------------------------------------------------------------------------------\n" + "4 18 \"MyPackage.MyClass1\" -> \"MyPackage.MyClass2\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerWithEmfTest method testChangeInXML.
@Test
public void testChangeInXML() {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#21 MyPackage.MyClass1"));
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\"/>\n" + "</ecore:EPackage>\n";
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file2.ecore", ecore));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
EPackage model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file2.ecore", EPackage.class);
ChangeSerializer serializer = serializerProvider.get();
serializer.addModification(model, (EPackage it) -> {
((EClass) model.getEClassifiers().get(0)).setName("NewClass");
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "---------------------------- 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=\"NewClass\"/>\n" + "</ecore:EPackage>\n" + "--------------------------------------------------------------------------------\n" + "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#21 <4:18|MyPackage.NewClass>\n" + "--------------------------------------------------------------------------------\n" + "4 18 \"MyPackage.MyClass1\" -> \"MyPackage.NewClass\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Aggregations