mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
[eclipse/xtext#1897] converted test code to java
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
parent
6fb07583b8
commit
78e6c56476
3 changed files with 631 additions and 1746 deletions
|
@ -0,0 +1,631 @@
|
|||
/**
|
||||
* Copyright (c) 2017, 2021 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.ide.tests.serializer;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess;
|
||||
import org.eclipse.xtext.ide.serializer.IChangeSerializer;
|
||||
import org.eclipse.xtext.ide.serializer.impl.ChangeSerializer;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryChild;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChild;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalValue;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.PartialSerializationTestLanguageFactory;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.WithTransientContainer;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.tests.PartialSerializationTestLanguageInjectorProvider;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.testing.util.InMemoryURIHandler;
|
||||
import org.eclipse.xtext.xbase.lib.Pair;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(PartialSerializationTestLanguageInjectorProvider.class)
|
||||
public class PartialSerializerTest {
|
||||
private PartialSerializationTestLanguageFactory fac = PartialSerializationTestLanguageFactory.eINSTANCE;
|
||||
|
||||
@Inject
|
||||
private Provider<ChangeSerializer> serializerProvider;
|
||||
|
||||
@Inject
|
||||
private ChangeSerializerTestHelper changeSerializerTestHelper;
|
||||
|
||||
@Test
|
||||
public void testMandatoryValueChange() {
|
||||
ITextRegionAccess diff = recordDiff(MandatoryValue.class, "#2 foo", (MandatoryValue it) -> {
|
||||
it.setName("bar");
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B MandatoryValue'bar' Model\n" +
|
||||
"0 2 S \"#2\" Model:'#2'\n" +
|
||||
"2 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"3 3 1 S \"bar\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'bar' Model\n" +
|
||||
"6 0 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"3 3 S \"foo\" MandatoryValue:name=ID\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalValueInsert() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalValue.class, "#3", (OptionalValue it) -> {
|
||||
it.setName("foo");
|
||||
});
|
||||
String expectation =
|
||||
"0 0 1 H\n" +
|
||||
" B OptionalValue'foo' Model\n" +
|
||||
"0 2 1 S \"#3\" Model:'#3'\n" +
|
||||
"2 0 1 H\n" +
|
||||
"2 3 1 S \"foo\" OptionalValue:name=ID\n" +
|
||||
" E OptionalValue'foo' Model\n" +
|
||||
"5 0 1 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"0 0 H\n" +
|
||||
"0 2 S \"#3\" Model:'#3'\n" +
|
||||
"2 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalValueChange() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalValue.class, "#3 foo", (OptionalValue it) -> {
|
||||
it.setName("baz");
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalValue'baz' Model\n" +
|
||||
"0 2 S \"#3\" Model:'#3'\n" +
|
||||
"2 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"3 3 1 S \"baz\" OptionalValue:name=ID\n" +
|
||||
" E OptionalValue'baz' Model\n" +
|
||||
"6 0 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"3 3 S \"foo\" OptionalValue:name=ID\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalValueRemove() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalValue.class, "#3 foo", (OptionalValue it) -> {
|
||||
it.setName(null);
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalValue Model\n" +
|
||||
"0 2 S \"#3\" Model:'#3'\n" +
|
||||
" E OptionalValue Model\n" +
|
||||
"2 1 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"2 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"3 3 S \"foo\" OptionalValue:name=ID\n" +
|
||||
"6 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildInsert() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChild.class, "#5", (OptionalChild it) -> {
|
||||
MandatoryValue newMandatoryValue = fac.createMandatoryValue();
|
||||
newMandatoryValue.setName("baz");
|
||||
it.setChild(newMandatoryValue);
|
||||
});
|
||||
String expectation =
|
||||
"0 0 1 H\n" +
|
||||
" B OptionalChild Model\n" +
|
||||
"0 2 1 S \"#5\" Model:'#5'\n" +
|
||||
"2 0 1 H\n" +
|
||||
" B MandatoryValue'baz' OptionalChild:child=MandatoryValue path:OptionalChild/child\n" +
|
||||
"2 3 1 S \"baz\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'baz' OptionalChild:child=MandatoryValue path:OptionalChild/child\n" +
|
||||
" E OptionalChild Model\n" +
|
||||
"5 0 1 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"0 0 H\n" +
|
||||
"0 2 S \"#5\" Model:'#5'\n" +
|
||||
"2 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildChange() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChild.class, "#5 foo", (OptionalChild it) -> {
|
||||
MandatoryValue newMandatoryValue = fac.createMandatoryValue();
|
||||
newMandatoryValue.setName("baz");
|
||||
it.setChild(newMandatoryValue);
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalChild Model\n" +
|
||||
"0 2 S \"#5\" Model:'#5'\n" +
|
||||
"2 1 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" B MandatoryValue'baz' MandatoryValue path:OptionalChild/child\n" +
|
||||
"3 3 1 S \"baz\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'baz' MandatoryValue path:OptionalChild/child\n" +
|
||||
" E OptionalChild 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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildRemove() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChild.class, "#5 foo", (OptionalChild it) -> {
|
||||
it.setChild(null);
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalChild Model\n" +
|
||||
"0 2 S \"#5\" Model:'#5'\n" +
|
||||
" E OptionalChild Model\n" +
|
||||
"2 1 1 H \" \" Whitespace:TerminalRule'WS'\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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveInList1() {
|
||||
ITextRegionAccess diff = recordDiff(Node.class, "#1 root { Foo; Bar; }", (Node it) -> {
|
||||
it.getChildren().move(0, 1);
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B Node'root' Model\n" +
|
||||
" 0 2 S \"#1\" Model:'#1'\n" +
|
||||
" 2 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" 3 4 S \"root\" Node:name=ID\n" +
|
||||
" 7 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" 8 1 S \"{\" Node:'{'\n" +
|
||||
" 9 1 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" B Node'Bar' Node:children+=Node path:Node'root'/children[0]\n" +
|
||||
"10 3 1 S \"Bar\" Node:name=ID\n" +
|
||||
"13 0 1 H\n" +
|
||||
"13 1 1 S \";\" Node:';'\n" +
|
||||
" E Node'Bar' Node:children+=Node path:Node'root'/children[0]\n" +
|
||||
"14 0 1 H\n" +
|
||||
" B Node'Foo' Node:children+=Node path:Node'root'/children[1]\n" +
|
||||
"14 3 S \"Foo\" Node:name=ID\n" +
|
||||
"17 0 H\n" +
|
||||
"17 1 S \";\" Node:';'\n" +
|
||||
" E Node'Foo' Node:children+=Node path:Node'root'/children[1]\n" +
|
||||
"18 2 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" 2 \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"20 1 S \"}\" Node:'}'\n" +
|
||||
" E Node'root' Model\n" +
|
||||
"21 0 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
" 9 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"10 3 S \"Foo\" Node:name=ID\n" +
|
||||
"------------ diff 2 ------------\n" +
|
||||
"14 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"15 3 S \"Bar\" Node:name=ID\n" +
|
||||
"18 0 H\n" +
|
||||
"18 1 S \";\" Node:';'\n" +
|
||||
"19 1 H \" \" Whitespace:TerminalRule'WS'\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildListInsertIntoEmpty() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13", (OptionalChildList it) -> {
|
||||
MandatoryValue newMandatoryValue = fac.createMandatoryValue();
|
||||
newMandatoryValue.setName("foo");
|
||||
it.getChildren().add(newMandatoryValue);
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalChildList Model\n" +
|
||||
"0 3 1 S \"#13\" Model:'#13'\n" +
|
||||
"3 0 1 H\n" +
|
||||
" B MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"3 3 1 S \"foo\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"6 0 1 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"0 3 S \"#13\" Model:'#13'\n" +
|
||||
"3 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildListInsertIntoEmpty2() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13", (OptionalChildList it) -> {
|
||||
MandatoryValue newMandatoryValue1 = fac.createMandatoryValue();
|
||||
newMandatoryValue1.setName("foo");
|
||||
it.getChildren().add(newMandatoryValue1);
|
||||
MandatoryValue newMandatoryValue2 = fac.createMandatoryValue();
|
||||
newMandatoryValue2.setName("bar");
|
||||
it.getChildren().add(newMandatoryValue2);
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalChildList Model\n" +
|
||||
"0 3 1 S \"#13\" Model:'#13'\n" +
|
||||
"3 0 1 H\n" +
|
||||
" B MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"3 3 1 S \"foo\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"6 0 1 H\n" +
|
||||
" B MandatoryValue'bar' MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
"6 3 1 S \"bar\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'bar' MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"9 0 1 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"0 3 S \"#13\" Model:'#13'\n" +
|
||||
"3 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildListInsertIntoFirst() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 x2", (OptionalChildList it) -> {
|
||||
MandatoryValue newMandatoryValue = fac.createMandatoryValue();
|
||||
newMandatoryValue.setName("x1");
|
||||
it.getChildren().add(0, newMandatoryValue);
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalChildList Model\n" +
|
||||
"0 3 S \"#13\" Model:'#13'\n" +
|
||||
"3 1 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" B MandatoryValue'x1' MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"4 2 1 S \"x1\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'x1' MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"6 0 1 H\n" +
|
||||
" B MandatoryValue'x2' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
"6 2 S \"x2\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'x2' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"8 0 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"3 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"4 2 S \"x2\" MandatoryValue:name=ID\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildListInsertIntoEndOne() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 x1", (OptionalChildList it) -> {
|
||||
MandatoryValue newMandatoryValue = fac.createMandatoryValue();
|
||||
newMandatoryValue.setName("x2");
|
||||
it.getChildren().add(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 1 S \"x1\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'x1' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"6 0 1 H\n" +
|
||||
" B MandatoryValue'x2' MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
"6 2 1 S \"x2\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'x2' MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"8 0 1 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"4 2 S \"x1\" MandatoryValue:name=ID\n" +
|
||||
"6 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildListInsertIntoEndTwo() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 a", (OptionalChildList it) -> {
|
||||
MandatoryValue newMandatoryValue1 = fac.createMandatoryValue();
|
||||
newMandatoryValue1.setName("b");
|
||||
it.getChildren().add(newMandatoryValue1);
|
||||
MandatoryValue newMandatoryValue2 = fac.createMandatoryValue();
|
||||
newMandatoryValue2.setName("c");
|
||||
it.getChildren().add(newMandatoryValue2);
|
||||
});
|
||||
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'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"4 1 1 S \"a\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"5 0 1 H\n" +
|
||||
" B MandatoryValue'b' MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
"5 1 1 S \"b\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'b' MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
"6 0 1 H\n" +
|
||||
" B MandatoryValue'c' MandatoryValue path:OptionalChildList/children[2]\n" +
|
||||
"6 1 1 S \"c\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'c' MandatoryValue path:OptionalChildList/children[2]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"7 0 1 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"4 1 S \"a\" MandatoryValue:name=ID\n" +
|
||||
"5 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildListInsertIntoEndThree() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 a", (OptionalChildList it) -> {
|
||||
MandatoryValue newMandatoryValue1 = fac.createMandatoryValue();
|
||||
newMandatoryValue1.setName("b");
|
||||
it.getChildren().add(newMandatoryValue1);
|
||||
MandatoryValue newMandatoryValue2 = fac.createMandatoryValue();
|
||||
newMandatoryValue2.setName("c");
|
||||
it.getChildren().add(newMandatoryValue2);
|
||||
MandatoryValue newMandatoryValue3 = fac.createMandatoryValue();
|
||||
newMandatoryValue3.setName("d");
|
||||
it.getChildren().add(newMandatoryValue3);
|
||||
});
|
||||
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'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"4 1 1 S \"a\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"5 0 1 H\n" +
|
||||
" B MandatoryValue'b' MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
"5 1 1 S \"b\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'b' MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
"6 0 1 H\n" +
|
||||
" B MandatoryValue'c' MandatoryValue path:OptionalChildList/children[2]\n" +
|
||||
"6 1 1 S \"c\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'c' MandatoryValue path:OptionalChildList/children[2]\n" +
|
||||
"7 0 1 H\n" +
|
||||
" B MandatoryValue'd' MandatoryValue path:OptionalChildList/children[3]\n" +
|
||||
"7 1 1 S \"d\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'd' MandatoryValue path:OptionalChildList/children[3]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"8 0 1 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"4 1 S \"a\" MandatoryValue:name=ID\n" +
|
||||
"5 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildRemoveListAllOne() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 x1", (OptionalChildList it) -> {
|
||||
EcoreUtil.remove(it.getChildren().get(0));
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalChildList Model\n" +
|
||||
"0 3 S \"#13\" Model:'#13'\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"3 1 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"3 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"4 2 S \"x1\" MandatoryValue:name=ID\n" +
|
||||
"6 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildRemoveListAllTwo() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 a b", (OptionalChildList it) -> {
|
||||
EcoreUtil.remove(it.getChildren().get(1));
|
||||
EcoreUtil.remove(it.getChildren().get(0));
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalChildList Model\n" +
|
||||
"0 3 S \"#13\" Model:'#13'\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"3 2 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" 2 \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"3 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"4 1 S \"a\" MandatoryValue:name=ID\n" +
|
||||
"5 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"------------ diff 2 ------------\n" +
|
||||
"5 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"6 1 S \"b\" MandatoryValue:name=ID\n" +
|
||||
"7 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildRemoveListFirstTwo() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 a b c", (OptionalChildList it) -> {
|
||||
EcoreUtil.remove(it.getChildren().get(1));
|
||||
EcoreUtil.remove(it.getChildren().get(0));
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B OptionalChildList Model\n" +
|
||||
"0 3 S \"#13\" Model:'#13'\n" +
|
||||
"3 2 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" 3 \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" B MandatoryValue'c' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"6 1 S \"c\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'c' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"7 0 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"3 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"4 1 S \"a\" MandatoryValue:name=ID\n" +
|
||||
"5 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"------------ diff 2 ------------\n" +
|
||||
"5 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"6 1 S \"b\" MandatoryValue:name=ID\n" +
|
||||
"7 1 H \" \" Whitespace:TerminalRule'WS'\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildRemoveListLastTwo() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 a b c", (OptionalChildList it) -> {
|
||||
EcoreUtil.remove(it.getChildren().get(2));
|
||||
EcoreUtil.remove(it.getChildren().get(1));
|
||||
});
|
||||
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'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"4 1 S \"a\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"5 2 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" 2 \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"5 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"6 1 S \"b\" MandatoryValue:name=ID\n" +
|
||||
"7 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"------------ diff 2 ------------\n" +
|
||||
"7 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"8 1 S \"c\" MandatoryValue:name=ID\n" +
|
||||
"9 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalChildRemoveListMiddleTwo() {
|
||||
ITextRegionAccess diff = recordDiff(OptionalChildList.class, "#13 a b c d", (OptionalChildList it) -> {
|
||||
EcoreUtil.remove(it.getChildren().get(2));
|
||||
EcoreUtil.remove(it.getChildren().get(1));
|
||||
});
|
||||
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'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"4 1 S \"a\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]\n" +
|
||||
"5 2 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" 3 \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" B MandatoryValue'd' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
"8 1 S \"d\" MandatoryValue:name=ID\n" +
|
||||
" E MandatoryValue'd' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]\n" +
|
||||
" E OptionalChildList Model\n" +
|
||||
"9 0 H\n" +
|
||||
"------------ diff 1 ------------\n" +
|
||||
"5 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"6 1 S \"b\" MandatoryValue:name=ID\n" +
|
||||
"7 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"------------ diff 2 ------------\n" +
|
||||
"7 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"8 1 S \"c\" MandatoryValue:name=ID\n" +
|
||||
"9 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
"\t\t";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransientValueChange() {
|
||||
ITextRegionAccess diff = recordDiff(WithTransientContainer.class, "#30 foo", (WithTransientContainer it) -> {
|
||||
it.getChild().setPackageName("bar");
|
||||
});
|
||||
String expectation =
|
||||
"0 0 H\n" +
|
||||
" B WithTransientContainer Model\n" +
|
||||
"0 3 S \"#30\" Model:'#30'\n" +
|
||||
"3 1 H \" \" Whitespace:TerminalRule'WS'\n" +
|
||||
" B WithTransient'foo' WithTransientContainer:child=WithTransient path:WithTransientContainer/child\n" +
|
||||
"4 3 S \"foo\" WithTransient:name=ID\n" +
|
||||
" E WithTransient'foo' WithTransientContainer:child=WithTransient path:WithTransientContainer/child\n" +
|
||||
" E WithTransientContainer Model\n" +
|
||||
"7 0 H\n";
|
||||
changeSerializerTestHelper.operator_tripleEquals(diff, expectation);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,576 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.tests.serializer
|
||||
|
||||
import com.google.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess
|
||||
import org.eclipse.xtext.ide.serializer.IChangeSerializer
|
||||
import org.eclipse.xtext.ide.serializer.impl.ChangeSerializer
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryChild
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChild
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalValue
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.PartialSerializationTestLanguageFactory
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.WithTransientContainer
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.tests.PartialSerializationTestLanguageInjectorProvider
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.eclipse.xtext.testing.util.InMemoryURIHandler
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(PartialSerializationTestLanguageInjectorProvider)
|
||||
class PartialSerializerTest {
|
||||
|
||||
extension PartialSerializationTestLanguageFactory fac = PartialSerializationTestLanguageFactory.eINSTANCE
|
||||
@Inject Provider<ChangeSerializer> serializerProvider
|
||||
@Inject extension ChangeSerializerTestHelper
|
||||
|
||||
@Test
|
||||
def void testMandatoryValueChange() {
|
||||
recordDiff(MandatoryValue, "#2 foo") [
|
||||
name = "bar"
|
||||
] === '''
|
||||
0 0 H
|
||||
B MandatoryValue'bar' Model
|
||||
0 2 S "#2" Model:'#2'
|
||||
2 1 H " " Whitespace:TerminalRule'WS'
|
||||
3 3 1 S "bar" MandatoryValue:name=ID
|
||||
E MandatoryValue'bar' Model
|
||||
6 0 H
|
||||
------------ diff 1 ------------
|
||||
3 3 S "foo" MandatoryValue:name=ID
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalValueInsert() {
|
||||
recordDiff(OptionalValue, "#3") [
|
||||
name = "foo"
|
||||
] === '''
|
||||
0 0 1 H
|
||||
B OptionalValue'foo' Model
|
||||
0 2 1 S "#3" Model:'#3'
|
||||
2 0 1 H
|
||||
2 3 1 S "foo" OptionalValue:name=ID
|
||||
E OptionalValue'foo' Model
|
||||
5 0 1 H
|
||||
------------ diff 1 ------------
|
||||
0 0 H
|
||||
0 2 S "#3" Model:'#3'
|
||||
2 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalValueChange() {
|
||||
recordDiff(OptionalValue, "#3 foo") [
|
||||
name = "baz"
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalValue'baz' Model
|
||||
0 2 S "#3" Model:'#3'
|
||||
2 1 H " " Whitespace:TerminalRule'WS'
|
||||
3 3 1 S "baz" OptionalValue:name=ID
|
||||
E OptionalValue'baz' Model
|
||||
6 0 H
|
||||
------------ diff 1 ------------
|
||||
3 3 S "foo" OptionalValue:name=ID
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalValueRemove() {
|
||||
recordDiff(OptionalValue, "#3 foo") [
|
||||
name = null
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalValue Model
|
||||
0 2 S "#3" Model:'#3'
|
||||
E OptionalValue Model
|
||||
2 1 1 H " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 1 ------------
|
||||
2 1 H " " Whitespace:TerminalRule'WS'
|
||||
3 3 S "foo" OptionalValue:name=ID
|
||||
6 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testMandatoryChildChange() {
|
||||
recordDiff(MandatoryChild, "#4 foo") [
|
||||
child = createMandatoryValue => [name = "baz"]
|
||||
] === '''
|
||||
0 0 H
|
||||
B MandatoryChild Model
|
||||
0 2 S "#4" Model:'#4'
|
||||
2 1 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'baz' MandatoryValue path:MandatoryChild/child
|
||||
3 3 1 S "baz" MandatoryValue:name=ID
|
||||
E MandatoryValue'baz' MandatoryValue path:MandatoryChild/child
|
||||
E MandatoryChild Model
|
||||
6 0 1 H
|
||||
------------ diff 1 ------------
|
||||
2 1 H " " Whitespace:TerminalRule'WS'
|
||||
3 3 S "foo" MandatoryValue:name=ID
|
||||
6 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildInsert() {
|
||||
recordDiff(OptionalChild, "#5") [
|
||||
child = createMandatoryValue => [name = "baz"]
|
||||
] === '''
|
||||
0 0 1 H
|
||||
B OptionalChild Model
|
||||
0 2 1 S "#5" Model:'#5'
|
||||
2 0 1 H
|
||||
B MandatoryValue'baz' OptionalChild:child=MandatoryValue path:OptionalChild/child
|
||||
2 3 1 S "baz" MandatoryValue:name=ID
|
||||
E MandatoryValue'baz' OptionalChild:child=MandatoryValue path:OptionalChild/child
|
||||
E OptionalChild Model
|
||||
5 0 1 H
|
||||
------------ diff 1 ------------
|
||||
0 0 H
|
||||
0 2 S "#5" Model:'#5'
|
||||
2 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildChange() {
|
||||
recordDiff(OptionalChild, "#5 foo") [
|
||||
child = createMandatoryValue => [name = "baz"]
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChild Model
|
||||
0 2 S "#5" Model:'#5'
|
||||
2 1 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'baz' MandatoryValue path:OptionalChild/child
|
||||
3 3 1 S "baz" MandatoryValue:name=ID
|
||||
E MandatoryValue'baz' MandatoryValue path:OptionalChild/child
|
||||
E OptionalChild Model
|
||||
6 0 1 H
|
||||
------------ diff 1 ------------
|
||||
2 1 H " " Whitespace:TerminalRule'WS'
|
||||
3 3 S "foo" MandatoryValue:name=ID
|
||||
6 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildRemove() {
|
||||
recordDiff(OptionalChild, "#5 foo") [
|
||||
child = null
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChild Model
|
||||
0 2 S "#5" Model:'#5'
|
||||
E OptionalChild Model
|
||||
2 1 1 H " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 1 ------------
|
||||
2 1 H " " Whitespace:TerminalRule'WS'
|
||||
3 3 S "foo" MandatoryValue:name=ID
|
||||
6 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testMoveInList1() {
|
||||
recordDiff(Node, "#1 root { Foo; Bar; }") [
|
||||
children.move(0, 1)
|
||||
] === '''
|
||||
0 0 H
|
||||
B Node'root' Model
|
||||
0 2 S "#1" Model:'#1'
|
||||
2 1 H " " Whitespace:TerminalRule'WS'
|
||||
3 4 S "root" Node:name=ID
|
||||
7 1 H " " Whitespace:TerminalRule'WS'
|
||||
8 1 S "{" Node:'{'
|
||||
9 1 1 H " " Whitespace:TerminalRule'WS'
|
||||
B Node'Bar' Node:children+=Node path:Node'root'/children[0]
|
||||
10 3 1 S "Bar" Node:name=ID
|
||||
13 0 1 H
|
||||
13 1 1 S ";" Node:';'
|
||||
E Node'Bar' Node:children+=Node path:Node'root'/children[0]
|
||||
14 0 1 H
|
||||
B Node'Foo' Node:children+=Node path:Node'root'/children[1]
|
||||
14 3 S "Foo" Node:name=ID
|
||||
17 0 H
|
||||
17 1 S ";" Node:';'
|
||||
E Node'Foo' Node:children+=Node path:Node'root'/children[1]
|
||||
18 2 H " " Whitespace:TerminalRule'WS'
|
||||
2 " " Whitespace:TerminalRule'WS'
|
||||
20 1 S "}" Node:'}'
|
||||
E Node'root' Model
|
||||
21 0 H
|
||||
------------ diff 1 ------------
|
||||
9 1 H " " Whitespace:TerminalRule'WS'
|
||||
10 3 S "Foo" Node:name=ID
|
||||
------------ diff 2 ------------
|
||||
14 1 H " " Whitespace:TerminalRule'WS'
|
||||
15 3 S "Bar" Node:name=ID
|
||||
18 0 H
|
||||
18 1 S ";" Node:';'
|
||||
19 1 H " " Whitespace:TerminalRule'WS'
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildListInsertIntoEmpty() {
|
||||
recordDiff(OptionalChildList, "#13") [
|
||||
children += createMandatoryValue => [name = "foo"]
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 1 S "#13" Model:'#13'
|
||||
3 0 1 H
|
||||
B MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]
|
||||
3 3 1 S "foo" MandatoryValue:name=ID
|
||||
E MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]
|
||||
E OptionalChildList Model
|
||||
6 0 1 H
|
||||
------------ diff 1 ------------
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildListInsertIntoEmpty2() {
|
||||
recordDiff(OptionalChildList, "#13") [
|
||||
children += createMandatoryValue => [name = "foo"]
|
||||
children += createMandatoryValue => [name = "bar"]
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 1 S "#13" Model:'#13'
|
||||
3 0 1 H
|
||||
B MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]
|
||||
3 3 1 S "foo" MandatoryValue:name=ID
|
||||
E MandatoryValue'foo' MandatoryValue path:OptionalChildList/children[0]
|
||||
6 0 1 H
|
||||
B MandatoryValue'bar' MandatoryValue path:OptionalChildList/children[1]
|
||||
6 3 1 S "bar" MandatoryValue:name=ID
|
||||
E MandatoryValue'bar' MandatoryValue path:OptionalChildList/children[1]
|
||||
E OptionalChildList Model
|
||||
9 0 1 H
|
||||
------------ diff 1 ------------
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildListInsertIntoFirst() {
|
||||
recordDiff(OptionalChildList, "#13 x2") [
|
||||
children.add(0, createMandatoryValue => [name = "x1"])
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 1 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'x1' MandatoryValue path:OptionalChildList/children[0]
|
||||
4 2 1 S "x1" MandatoryValue:name=ID
|
||||
E MandatoryValue'x1' MandatoryValue path:OptionalChildList/children[0]
|
||||
6 0 1 H
|
||||
B MandatoryValue'x2' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]
|
||||
6 2 S "x2" MandatoryValue:name=ID
|
||||
E MandatoryValue'x2' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]
|
||||
E OptionalChildList Model
|
||||
8 0 H
|
||||
------------ diff 1 ------------
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
4 2 S "x2" MandatoryValue:name=ID
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildListInsertIntoMiddle() {
|
||||
recordDiff(OptionalChildList, "#13 x1 x3") [
|
||||
children.add(1, createMandatoryValue => [name = "x2"])
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'x1' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
4 2 S "x1" MandatoryValue:name=ID
|
||||
E MandatoryValue'x1' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
6 1 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'x2' MandatoryValue path:OptionalChildList/children[1]
|
||||
7 2 1 S "x2" MandatoryValue:name=ID
|
||||
E MandatoryValue'x2' MandatoryValue path:OptionalChildList/children[1]
|
||||
9 0 1 H
|
||||
B MandatoryValue'x3' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[2]
|
||||
9 2 S "x3" MandatoryValue:name=ID
|
||||
E MandatoryValue'x3' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[2]
|
||||
E OptionalChildList Model
|
||||
11 0 H
|
||||
------------ diff 1 ------------
|
||||
6 1 H " " Whitespace:TerminalRule'WS'
|
||||
7 2 S "x3" MandatoryValue:name=ID
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildListInsertIntoEndOne() {
|
||||
recordDiff(OptionalChildList, "#13 x1") [
|
||||
children += createMandatoryValue => [name = "x2"]
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'x1' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
4 2 1 S "x1" MandatoryValue:name=ID
|
||||
E MandatoryValue'x1' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
6 0 1 H
|
||||
B MandatoryValue'x2' MandatoryValue path:OptionalChildList/children[1]
|
||||
6 2 1 S "x2" MandatoryValue:name=ID
|
||||
E MandatoryValue'x2' MandatoryValue path:OptionalChildList/children[1]
|
||||
E OptionalChildList Model
|
||||
8 0 1 H
|
||||
------------ diff 1 ------------
|
||||
4 2 S "x1" MandatoryValue:name=ID
|
||||
6 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildListInsertIntoEndTwo() {
|
||||
recordDiff(OptionalChildList, "#13 a") [
|
||||
children += createMandatoryValue => [name = "b"]
|
||||
children += createMandatoryValue => [name = "c"]
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
4 1 1 S "a" MandatoryValue:name=ID
|
||||
E MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
5 0 1 H
|
||||
B MandatoryValue'b' MandatoryValue path:OptionalChildList/children[1]
|
||||
5 1 1 S "b" MandatoryValue:name=ID
|
||||
E MandatoryValue'b' MandatoryValue path:OptionalChildList/children[1]
|
||||
6 0 1 H
|
||||
B MandatoryValue'c' MandatoryValue path:OptionalChildList/children[2]
|
||||
6 1 1 S "c" MandatoryValue:name=ID
|
||||
E MandatoryValue'c' MandatoryValue path:OptionalChildList/children[2]
|
||||
E OptionalChildList Model
|
||||
7 0 1 H
|
||||
------------ diff 1 ------------
|
||||
4 1 S "a" MandatoryValue:name=ID
|
||||
5 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildListInsertIntoEndThree() {
|
||||
recordDiff(OptionalChildList, "#13 a") [
|
||||
children += createMandatoryValue => [name = "b"]
|
||||
children += createMandatoryValue => [name = "c"]
|
||||
children += createMandatoryValue => [name = "d"]
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
4 1 1 S "a" MandatoryValue:name=ID
|
||||
E MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
5 0 1 H
|
||||
B MandatoryValue'b' MandatoryValue path:OptionalChildList/children[1]
|
||||
5 1 1 S "b" MandatoryValue:name=ID
|
||||
E MandatoryValue'b' MandatoryValue path:OptionalChildList/children[1]
|
||||
6 0 1 H
|
||||
B MandatoryValue'c' MandatoryValue path:OptionalChildList/children[2]
|
||||
6 1 1 S "c" MandatoryValue:name=ID
|
||||
E MandatoryValue'c' MandatoryValue path:OptionalChildList/children[2]
|
||||
7 0 1 H
|
||||
B MandatoryValue'd' MandatoryValue path:OptionalChildList/children[3]
|
||||
7 1 1 S "d" MandatoryValue:name=ID
|
||||
E MandatoryValue'd' MandatoryValue path:OptionalChildList/children[3]
|
||||
E OptionalChildList Model
|
||||
8 0 1 H
|
||||
------------ diff 1 ------------
|
||||
4 1 S "a" MandatoryValue:name=ID
|
||||
5 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildRemoveListAllOne() {
|
||||
recordDiff(OptionalChildList, "#13 x1") [
|
||||
EcoreUtil.remove(children.get(0))
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
E OptionalChildList Model
|
||||
3 1 1 H " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 1 ------------
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
4 2 S "x1" MandatoryValue:name=ID
|
||||
6 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildRemoveListAllTwo() {
|
||||
recordDiff(OptionalChildList, "#13 a b") [
|
||||
EcoreUtil.remove(children.get(1))
|
||||
EcoreUtil.remove(children.get(0))
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
E OptionalChildList Model
|
||||
3 2 H " " Whitespace:TerminalRule'WS'
|
||||
2 " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 1 ------------
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
4 1 S "a" MandatoryValue:name=ID
|
||||
5 1 H " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 2 ------------
|
||||
5 1 H " " Whitespace:TerminalRule'WS'
|
||||
6 1 S "b" MandatoryValue:name=ID
|
||||
7 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildRemoveListFirstTwo() {
|
||||
recordDiff(OptionalChildList, "#13 a b c") [
|
||||
EcoreUtil.remove(children.get(1))
|
||||
EcoreUtil.remove(children.get(0))
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 2 H " " Whitespace:TerminalRule'WS'
|
||||
" " Whitespace:TerminalRule'WS'
|
||||
3 " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'c' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
6 1 S "c" MandatoryValue:name=ID
|
||||
E MandatoryValue'c' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
E OptionalChildList Model
|
||||
7 0 H
|
||||
------------ diff 1 ------------
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
4 1 S "a" MandatoryValue:name=ID
|
||||
5 1 H " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 2 ------------
|
||||
5 1 H " " Whitespace:TerminalRule'WS'
|
||||
6 1 S "b" MandatoryValue:name=ID
|
||||
7 1 H " " Whitespace:TerminalRule'WS'
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildRemoveListLastTwo() {
|
||||
recordDiff(OptionalChildList, "#13 a b c") [
|
||||
EcoreUtil.remove(children.get(2))
|
||||
EcoreUtil.remove(children.get(1))
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
4 1 S "a" MandatoryValue:name=ID
|
||||
E MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
E OptionalChildList Model
|
||||
5 2 H " " Whitespace:TerminalRule'WS'
|
||||
2 " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 1 ------------
|
||||
5 1 H " " Whitespace:TerminalRule'WS'
|
||||
6 1 S "b" MandatoryValue:name=ID
|
||||
7 1 H " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 2 ------------
|
||||
7 1 H " " Whitespace:TerminalRule'WS'
|
||||
8 1 S "c" MandatoryValue:name=ID
|
||||
9 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testOptionalChildRemoveListMiddleTwo() {
|
||||
recordDiff(OptionalChildList, "#13 a b c d") [
|
||||
EcoreUtil.remove(children.get(2))
|
||||
EcoreUtil.remove(children.get(1))
|
||||
] === '''
|
||||
0 0 H
|
||||
B OptionalChildList Model
|
||||
0 3 S "#13" Model:'#13'
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
4 1 S "a" MandatoryValue:name=ID
|
||||
E MandatoryValue'a' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[0]
|
||||
5 2 H " " Whitespace:TerminalRule'WS'
|
||||
" " Whitespace:TerminalRule'WS'
|
||||
3 " " Whitespace:TerminalRule'WS'
|
||||
B MandatoryValue'd' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]
|
||||
8 1 S "d" MandatoryValue:name=ID
|
||||
E MandatoryValue'd' OptionalChildList:children+=MandatoryValue path:OptionalChildList/children[1]
|
||||
E OptionalChildList Model
|
||||
9 0 H
|
||||
------------ diff 1 ------------
|
||||
5 1 H " " Whitespace:TerminalRule'WS'
|
||||
6 1 S "b" MandatoryValue:name=ID
|
||||
7 1 H " " Whitespace:TerminalRule'WS'
|
||||
------------ diff 2 ------------
|
||||
7 1 H " " Whitespace:TerminalRule'WS'
|
||||
8 1 S "c" MandatoryValue:name=ID
|
||||
9 1 H " " Whitespace:TerminalRule'WS'
|
||||
'''
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testTransientValueChange() {
|
||||
recordDiff(WithTransientContainer, "#30 foo") [
|
||||
child.packageName = "bar"
|
||||
] === '''
|
||||
0 0 H
|
||||
B WithTransientContainer Model
|
||||
0 3 S "#30" Model:'#30'
|
||||
3 1 H " " Whitespace:TerminalRule'WS'
|
||||
B WithTransient'foo' WithTransientContainer:child=WithTransient path:WithTransientContainer/child
|
||||
4 3 S "foo" WithTransient:name=ID
|
||||
E WithTransient'foo' WithTransientContainer:child=WithTransient path:WithTransientContainer/child
|
||||
E WithTransientContainer Model
|
||||
7 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
def private <T extends EObject> ITextRegionAccess recordDiff(Class<T> modelType, CharSequence modelText,
|
||||
IChangeSerializer.IModification<T> modification) {
|
||||
val fs = new InMemoryURIHandler()
|
||||
fs += "inmemory:/file1.pstl" -> modelText.toString
|
||||
|
||||
val rs = fs.createResourceSet
|
||||
val model = rs.findFirstOfTypeInFile("inmemory:/file1.pstl", modelType)
|
||||
|
||||
val serializer = serializerProvider.get()
|
||||
serializer.addModification(model, modification)
|
||||
return serializer.endRecordChangesToTextRegions
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue