Search in sources :

Example 16 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class ChangeSerializerTest method testInsertOneChild.

@Test
public void testInsertOneChild() {
    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 newNode = fac.createNode();
        newNode.setName("bazz");
        model.getChildren().get(0).getChildren().add(newNode);
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root { child1 { foo1; <25:0|bazz; >} }\n" + "--------------------------------------------------------------------------------\n" + "25 0 \"\" -> \"bazz; \"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 17 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class ChangeSerializerTest method testDeleteTwoChildren.

@Test
public void testDeleteTwoChildren() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#1 root { child1; child2; }"));
    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) -> {
        EcoreUtil.remove(model.getChildren().get(1));
        EcoreUtil.remove(model.getChildren().get(0));
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root { <10:7|> <18:7|> }\n" + "--------------------------------------------------------------------------------\n" + "10 7 \"child1;\" -> \"\"\n" + "18 7 \"child2;\" -> \"\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 18 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class ChangeSerializerTest method testRenameFqn1ValueConversion.

@Test
public void testRenameFqn1ValueConversion() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content = "#1 r {\n" + "	X refs ^a1.^a2 ^X.^a1.^a2 ^r.^X.^a1.^a2 { a1 { a2 refs ^a2 { a3 { ref ^a3 } } } }\n" + "	Y refs ^b1.^b2 ^Y.^b1.^b2 ^r.^Y.^b1.^b2 { b1 { b2 { ref b2 } } }\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 node = model.getChildren().get(0).getChildren().get(0).getChildren().get(0);
        node.setName("b");
    });
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 r {\n" + "	X refs <15:7|a1.b> <23:10|a1.b> <34:13|a1.b> { a1 { <55:2|b> refs <63:3|b> { a3 { ref ^a3 } } } }\n" + "	Y refs ^b1.^b2 ^Y.^b1.^b2 ^r.^Y.^b1.^b2 { b1 { b2 { ref b2 } } }\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "15  7 \"^a1.^a2\" -> \"a1.b\"\n" + "23 10 \"^X.^a1.^a2\" -> \"a1.b\"\n" + "34 13 \"^r.^X.^a1.^a2\" -> \"a1.b\"\n" + "55  2 \"a2\" -> \"b\"\n" + "63  3 \"^a2\" -> \"b\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 19 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class ChangeSerializerTest method testTwoChildren.

@Test
public void testTwoChildren() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#1 root { foo1; foo2; }"));
    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");
        model.getChildren().get(1).setName("bazz5");
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root { <10:4|bazz4>; <16:4|bazz5>; }\n" + "--------------------------------------------------------------------------------\n" + "10 4 \"foo1\" -> \"bazz4\"\n" + "16 4 \"foo2\" -> \"bazz5\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 20 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class ChangeSerializerTest method testDeleteChild.

@Test
public void testDeleteChild() {
    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) -> {
        EcoreUtil.remove(model.getChildren().get(0).getChildren().get(0));
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#1 root { child1 { <19:5|> } }\n" + "--------------------------------------------------------------------------------\n" + "19 5 \"foo1;\" -> \"\"\n";
    changeSerializerTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Aggregations

InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)32 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)29 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)26 Test (org.junit.Test)26 Resource (org.eclipse.emf.ecore.resource.Resource)22 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)20 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)12 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)10 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)5 TwoChildLists (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists)4 PackageDeclaration (org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)4 EClass (org.eclipse.emf.ecore.EClass)3 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 ChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions)2 EPackage (org.eclipse.emf.ecore.EPackage)1