Search in sources :

Example 1 with MandatoryValue

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue in project xtext-core by eclipse.

the class ChangeSerializerTest method testSimple.

@Test
public void testSimple() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    changeSerializerTestHelper.operator_add(fs, Pair.of("inmemory:/file1.pstl", "#2 foo"));
    ResourceSet rs = changeSerializerTestHelper.createResourceSet(fs);
    MandatoryValue model = changeSerializerTestHelper.findFirstOfTypeInFile(rs, "inmemory:/file1.pstl", MandatoryValue.class);
    IChangeSerializer serializer = changeSerializerTestHelper.newChangeSerializer();
    serializer.addModification(model.eResource(), (Resource it) -> {
        model.setName("bar");
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------\n" + "#2 <3:3|bar>\n" + "--------------------------------------------------------------------------------\n" + "3 3 \"foo\" -> \"bar\"\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) 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 2 with MandatoryValue

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue in project xtext-core by eclipse.

the class ChangeSerializerTest method testMoveElement_2.

@Test
public void testMoveElement_2() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content = "#22 {\n" + "	child1\n" + "	children1 {\n" + "		child2 jumper\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) -> {
        model.getDirectChildren().add(0, IterableExtensions.findFirst(model.getChildsList().getChildren(), (MandatoryValue v) -> "jumper".equals(v.getName())));
    });
    Collection<IEmfResourceChange> changes = changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "--------------- inmemory:/file-move.pstl (syntax: <offset|text>) ---------------\n" + "#22 {<5:0| jumper>\n" + "	child1\n" + "	children1 {\n" + "		child2 <36:6|>\n" + "	}\n" + "}\n" + "--------------------------------------------------------------------------------\n" + " 5 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 3 with MandatoryValue

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue 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 4 with MandatoryValue

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue in project xtext-core by eclipse.

the class PartialSerializerTest method testOptionalChildListInsertIntoMiddle.

@Test
public void testOptionalChildListInsertIntoMiddle() {
    ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 x1 x3", (OptionalChildList it) -> {
        MandatoryValue newMandatoryValue = fac.createMandatoryValue();
        newMandatoryValue.setName("x2");
        it.getChildren().add(1, newMandatoryValue);
    });
    String expectation = "0 0   H\n" + "       B OptionalChildList    Model\n" + " 0 3    S \"#13\"                Model:'#13'\n" + " 3 1    H \" \"                  Whitespace:TerminalRule'WS'\n" + "        B MandatoryValue'x1'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + " 4 2     S \"x1\"                 MandatoryValue:name=ID\n" + "        E MandatoryValue'x1'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" + " 6 1 1  H \" \"                  Whitespace:TerminalRule'WS'\n" + "        B MandatoryValue'x2'   MandatoryValue path:OptionalChildList/children[1]\n" + " 7 2 1   S \"x2\"                 MandatoryValue:name=ID\n" + "        E MandatoryValue'x2'   MandatoryValue path:OptionalChildList/children[1]\n" + " 9 0 1  H\n" + "        B MandatoryValue'x3'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[2]\n" + " 9 2     S \"x3\"                 MandatoryValue:name=ID\n" + "        E MandatoryValue'x3'   OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[2]\n" + "       E OptionalChildList    Model\n" + "11 0   H\n" + "------------ diff 1 ------------\n" + " 6 1  H \" \"                  Whitespace:TerminalRule'WS'\n" + " 7 2  S \"x3\"                 MandatoryValue:name=ID\n";
    changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) OptionalChildList(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) Test(org.junit.Test)

Example 5 with MandatoryValue

use of org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue in project xtext-core by eclipse.

the class PartialSerializerTest method testMandatoryChildChange.

@Test
public void testMandatoryChildChange() {
    ITextRegionAccess diff = recordDiff(MandatoryChild.class, "#4 foo", (MandatoryChild it) -> {
        MandatoryValue newMandatoryValue = fac.createMandatoryValue();
        newMandatoryValue.setName("baz");
        it.setChild(newMandatoryValue);
    });
    String expectation = "0 0   H\n" + "      B MandatoryChild       Model\n" + "0 2    S \"#4\"                 Model:'#4'\n" + "2 1 1  H \" \"                  Whitespace:TerminalRule'WS'\n" + "       B MandatoryValue'baz'  MandatoryValue path:MandatoryChild/child\n" + "3 3 1   S \"baz\"                MandatoryValue:name=ID\n" + "       E MandatoryValue'baz'  MandatoryValue path:MandatoryChild/child\n" + "      E MandatoryChild       Model\n" + "6 0 1 H\n" + "------------ diff 1 ------------\n" + "2 1  H \" \"                  Whitespace:TerminalRule'WS'\n" + "3 3  S \"foo\"                MandatoryValue:name=ID\n" + "6 0  H\n";
    changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) MandatoryValue(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue) MandatoryChild(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryChild) Test(org.junit.Test)

Aggregations

MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)19 Test (org.junit.Test)16 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)11 OptionalChildList (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList)7 Resource (org.eclipse.emf.ecore.resource.Resource)5 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)5 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)5 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)5 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)5 TwoChildLists (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 OptionalChild (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChild)2 MandatoryChild (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryChild)1