Search in sources :

Example 26 with InMemoryURIHandler

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

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

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);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) Model(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Model) 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 29 with InMemoryURIHandler

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);
}
Also used : ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) 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 30 with InMemoryURIHandler

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);
}
Also used : ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

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