Search in sources :

Example 21 with InMemoryURIHandler

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);
}
Also used : MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) TwoChildLists(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists) 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 22 with InMemoryURIHandler

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);
}
Also used : MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) TwoChildLists(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists) 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 23 with InMemoryURIHandler

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);
}
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 24 with InMemoryURIHandler

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);
}
Also used : ChildWithSubChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.ChildWithSubChild) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Resource(org.eclipse.emf.ecore.resource.Resource) ChildWithSubChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.ChildWithSubChild) SubChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.SubChild) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ChildWithSubChilds(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.ChildWithSubChilds) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 25 with InMemoryURIHandler

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);
}
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