use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTest method testAddChildElement.
@Test
public void testAddChildElement() {
InMemoryURIHandler fs = new InMemoryURIHandler();
String content = "#22 {\n" + " child1\n" + " children1 {\n" + " child2 child3\n" + " }\n" + "}";
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file-move.pstl", content));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
TwoChildLists model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file-move.pstl", TwoChildLists.class);
IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
serializer.addModification(model.eResource(), (Resource it) -> {
MandatoryValue newMandatoryValue = fac.createMandatoryValue();
newMandatoryValue.setName("newChild");
model.getDirectChildren().add(newMandatoryValue);
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "--------------- inmemory:/file-move.pstl (syntax: <offset|text>) ---------------\n" + "#22 {\n" + " child1<13:0| newChild>\n" + " children1 {\n" + " child2 child3\n" + " }\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "13 0 \"\" -> \" newChild\"\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.
@Test
public void testMoveElement() {
InMemoryURIHandler fs = new InMemoryURIHandler();
String content = "#22 {\n" + " child1\n" + " children1 {\n" + " child2 jumper\n" + " }\n" + "}";
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file-move1.pstl", content));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
TwoChildLists model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file-move1.pstl", TwoChildLists.class);
IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
serializer.addModification(model.eResource(), (Resource it) -> {
model.getDirectChildren().add(IterableExtensions.findFirst(model.getChildsList().getChildren(), (MandatoryValue v) -> "jumper".equals(v.getName())));
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "-------------- inmemory:/file-move1.pstl (syntax: <offset|text>) ---------------\n" + "#22 {\n" + " child1<13:0| jumper>\n" + " children1 {\n" + " child2 <36:6|>\n" + " }\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "13 0 \"\" -> \" jumper\"\n" + "36 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 testInsertBeforeComment.
@Test
public void testInsertBeforeComment() {
InMemoryURIHandler fs = new InMemoryURIHandler();
String content = "#1 root {\n" + " /**/ \n" + " child1;\n" + "}\n";
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", content));
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) -> {
Node newNode = fac.createNode();
newNode.setName("bazz");
model.getChildren().add(0, newNode);
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root {<9:0| bazz;>\n" + " /**/ \n" + " child1;\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "9 0 \"\" -> \" bazz;\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTest method testAddElements.
@Test
public void testAddElements() {
String uri = "inmemory:/file-add.pstl";
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of(uri, "#23"));
ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
ChildWithSubChilds model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, uri, ChildWithSubChilds.class);
IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
serializer.addModification(model.eResource(), (Resource it) -> {
ChildWithSubChild newChildWithSubChild = fac.createChildWithSubChild();
SubChild newSubChild1 = fac.createSubChild();
newSubChild1.setName("A");
newChildWithSubChild.getSubChilds().add(newSubChild1);
model.getChildren().add(newChildWithSubChild);
SubChild newSubChild = fac.createSubChild();
newSubChild.setName("A2");
model.getChildren().get(0).getSubChilds().add(newSubChild);
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "--------------- inmemory:/file-add.pstl (syntax: <offset|text>) ----------------\n" + "<0:3|#23 subs A A2>\n" + "--------------------------------------------------------------------------------\n" + "0 3 \"#23\" -> \"#23 subs A A2\"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTest method testInsertTwoChild.
@Test
public void testInsertTwoChild() {
InMemoryURIHandler fs = new InMemoryURIHandler();
changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#1 root { child1 { 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) -> {
Node newNode1 = fac.createNode();
newNode1.setName("bazz1");
model.getChildren().get(0).getChildren().add(newNode1);
Node newNode2 = fac.createNode();
newNode2.setName("bazz2");
model.getChildren().get(0).getChildren().add(newNode2);
});
Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root { child1 { foo1; <25:0|bazz1; bazz2; >} }\n" + "--------------------------------------------------------------------------------\n" + "25 0 \"\" -> \"bazz1; bazz2; \"\n";
changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Aggregations