-
Notifications
You must be signed in to change notification settings - Fork 316
/
AbstractCompositeNodeTest.java
106 lines (91 loc) · 3.57 KB
/
AbstractCompositeNodeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*******************************************************************************
* Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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.nodemodel;
import static org.eclipse.xtext.nodemodel.NodeModelAccessForTests.*;
import static org.junit.Assert.*;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.xtext.nodemodel.impl.AbstractNode;
import org.eclipse.xtext.nodemodel.impl.LeafNode;
import org.eclipse.xtext.nodemodel.impl.NodeModelBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
public abstract class AbstractCompositeNodeTest {
private NodeModelBuilder mutator;
public abstract void testTextOffsetLength();
protected abstract ICompositeNode createCompositeNode();
protected abstract AbstractNode getFirstChild(ICompositeNode node);
protected final void addChild(ICompositeNode composite, AbstractNode leaf) {
mutator.addChild(composite, leaf);
}
@Before
public void setUp() throws Exception {
this.mutator = new NodeModelBuilder();
}
@After
public void tearDown() throws Exception {
this.mutator = null;
}
@Test public void testAddChild_00() {
ICompositeNode composite = createCompositeNode();
LeafNode first = new LeafNode();
addChild(composite, first);
assertSame(first, getFirstChild(composite));
assertSame(composite, first.getParent());
assertSame(first, basicGetNextSibling(first));
assertSame(first, basicGetPreviousSibling(first));
}
@Test public void testAddChild_01() {
ICompositeNode composite = createCompositeNode();
LeafNode first = new LeafNode();
LeafNode second = new LeafNode();
addChild(composite, first);
addChild(composite, second);
assertSame(first, getFirstChild(composite));
assertSame(second, first.getNextSibling());
assertSame(second, basicGetPreviousSibling(first));
assertSame(first, second.getPreviousSibling());
assertSame(first, basicGetNextSibling(second));
assertSame(composite, first.getParent());
assertSame(composite, second.getParent());
}
@Test public void testAddChild_02() {
ICompositeNode composite = createCompositeNode();
LeafNode first = new LeafNode();
LeafNode second = new LeafNode();
LeafNode third = new LeafNode();
addChild(composite, first);
addChild(composite, second);
addChild(composite, third);
assertSame(first, getFirstChild(composite));
assertSame(second, first.getNextSibling());
assertSame(third, second.getNextSibling());
assertSame(first, basicGetNextSibling(third));
assertSame(third, basicGetPreviousSibling(first));
assertSame(second, third.getPreviousSibling());
assertSame(first, second.getPreviousSibling());
assertSame(composite, first.getParent());
assertSame(composite, second.getParent());
assertSame(composite, third.getParent());
}
@Test public void testActsAsAdapter() {
EObject object = EcoreFactory.eINSTANCE.createEObject();
ICompositeNode composite = createCompositeNode();
object.eAdapters().add((Adapter) composite);
assertSame(object, composite.getSemanticElement());
assertSame(object, ((Adapter) composite).getTarget());
object.eAdapters().clear();
assertNull(composite.getSemanticElement());
}
}