Search in sources :

Example 6 with InMemoryURIHandler

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

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

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

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);
}
Also used : EClassRef(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.EClassRef) EClass(org.eclipse.emf.ecore.EClass) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 10 with InMemoryURIHandler

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