-
Notifications
You must be signed in to change notification settings - Fork 316
/
BasicNodeIterableTest.java
58 lines (48 loc) · 1.75 KB
/
BasicNodeIterableTest.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
/*******************************************************************************
* Copyright (c) 2020 Robert Lewis 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 java.util.ArrayList;
import java.util.List;
import org.eclipse.xtext.nodemodel.impl.AbstractNode;
import org.eclipse.xtext.nodemodel.impl.BasicNodeIterable;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Robert Lewis - Initial contribution and API
*/
public class BasicNodeIterableTest {
@Test
public void forEachTest() {
AbstractNode alpha = BasicNodeIteratorTest.nodeWithTwoSiblings();
BasicNodeIterable iterable = new BasicNodeIterable(alpha);
List<String> tokens = new ArrayList<String>();
for (INode node : iterable) {
tokens.add(node.getText());
}
Assert.assertEquals("alpha", tokens.get(0));
Assert.assertEquals("beta", tokens.get(1));
Assert.assertEquals("gamma", tokens.get(2));
}
@Test
public void forEachReverseTest() {
AbstractNode alpha = BasicNodeIteratorTest.nodeWithTwoSiblings();
BasicNodeIterable iterable = new BasicNodeIterable(alpha);
List<String> tokens = new ArrayList<String>();
for (INode node : iterable.reverse()) {
tokens.add(node.getText());
}
Assert.assertEquals("gamma", tokens.get(0));
Assert.assertEquals("beta", tokens.get(1));
Assert.assertEquals("alpha", tokens.get(2));
}
@Test(expected=NullPointerException.class)
public void testStartWithNullThrowsNPE() {
new BasicNodeIterable(null);
}
}