Skip to main content
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorpelder2008-05-04 19:17:40 -0400
committerpelder2008-05-04 19:17:40 -0400
commitd8e878910e6a537528be4f45ad30407a31f9305c (patch)
tree6767dc5bd99ddbd547ce2a59817a4fa30f1540ae /tests
parent21a12ef56bfd30e6e7d2ad6dd6cf3883917516c9 (diff)
downloadorg.eclipse.jet-d8e878910e6a537528be4f45ad30407a31f9305c.tar.gz
org.eclipse.jet-d8e878910e6a537528be4f45ad30407a31f9305c.tar.xz
org.eclipse.jet-d8e878910e6a537528be4f45ad30407a31f9305c.zip
[175783] Unable to use certain xpath axes in jet tags
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java47
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AncestorOrSelfTests.java86
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AncestorTests.java82
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DescendantTests.java60
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/FollowingSiblingTests.java79
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/FollowingTests.java102
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/PrecedingSiblingTests.java76
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/PrecedingTests.java116
8 files changed, 628 insertions, 20 deletions
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java
index 6d10fc7..f41f8d9 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java
@@ -8,34 +8,41 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.eclipse.jet.tests.xpath");
//$JUnit-BEGIN$
- suite.addTestSuite(XPathParserTests.class);
- suite.addTestSuite(EStructuralFeatureSettingTests.class);
- suite.addTestSuite(VariableTests.class);
+ suite.addTestSuite(EMFResourceInspectorTests.class);
+ suite.addTestSuite(AncestorTests.class);
suite.addTestSuite(RelOpTests.class);
- suite.addTest(ResourceAttributeInspectorTests.suite());
- suite.addTestSuite(SelfStepTests.class);
- suite.addTestSuite(ParentStepTests.class);
- suite.addTestSuite(DescendantOrSelfTests.class);
suite.addTestSuite(LogicalOpTests.class);
- suite.addTestSuite(DOMInspectorTests.class);
- suite.addTestSuite(ExpandedNameTests.class);
- suite.addTestSuite(XPathOverDOMTests.class);
+ suite.addTestSuite(XPathTokenScannerTests.class);
suite.addTestSuite(BooleanFunctionTests.class);
- suite.addTestSuite(EMFResourceInspectorTests.class);
- suite.addTestSuite(NumberBinaryOpTests.class);
+ suite.addTestSuite(XPathOverDOMTests.class);
+ suite.addTest(ResourceAttributeInspectorTests.suite());
+ suite.addTestSuite(PrecedingTests.class);
+ suite.addTestSuite(FollowingSiblingTests.class);
+ suite.addTestSuite(XPathParserDefects.class);
+ suite.addTestSuite(EObjectInspectorTests.class);
suite.addTest(ResourceInspectorTests.suite());
- suite.addTestSuite(StringFunctionTests.class);
- suite.addTestSuite(BuiltinStringFunctionsTests.class);
+ suite.addTestSuite(XPathOverEcoreTests.class);
+ suite.addTestSuite(XPathInspectorManagerTests.class);
suite.addTestSuite(NumberFunctionTests.class);
+ suite.addTestSuite(BuiltinStringFunctionsTests.class);
+ suite.addTestSuite(EStructuralFeatureSettingTests.class);
suite.addTestSuite(XPathOverEmfXmlXsdTests.class);
- suite.addTestSuite(XPathParserDefects.class);
+ suite.addTestSuite(AncestorOrSelfTests.class);
+ suite.addTestSuite(NumberBinaryOpTests.class);
+ suite.addTestSuite(RootTests.class);
+ suite.addTestSuite(DOMInspectorTests.class);
+ suite.addTestSuite(DescendantTests.class);
+ suite.addTestSuite(SelfStepTests.class);
+ suite.addTestSuite(DescendantOrSelfTests.class);
+ suite.addTestSuite(FollowingTests.class);
+ suite.addTestSuite(StringFunctionTests.class);
+ suite.addTestSuite(ParentStepTests.class);
+ suite.addTestSuite(XPathParserTests.class);
suite.addTestSuite(ChildStepTests.class);
+ suite.addTestSuite(PrecedingSiblingTests.class);
+ suite.addTestSuite(VariableTests.class);
suite.addTestSuite(AttributeStepTests.class);
- suite.addTestSuite(XPathOverEcoreTests.class);
- suite.addTestSuite(EObjectInspectorTests.class);
- suite.addTestSuite(XPathInspectorManagerTests.class);
- suite.addTestSuite(XPathTokenScannerTests.class);
- suite.addTestSuite(RootTests.class);
+ suite.addTestSuite(ExpandedNameTests.class);
//$JUnit-END$
return suite;
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AncestorOrSelfTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AncestorOrSelfTests.java
new file mode 100644
index 0000000..86f3786
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AncestorOrSelfTests.java
@@ -0,0 +1,86 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: AncestorOrSelfTests.java,v 1.1 2008/05/04 23:17:40 pelder Exp $
+ */
+
+package org.eclipse.jet.tests.xpath;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.jet.internal.xpath.ast.Axis;
+import org.eclipse.jet.internal.xpath.ast.ContextNode;
+import org.eclipse.jet.internal.xpath.ast.NodeTest;
+import org.eclipse.jet.internal.xpath.ast.Step;
+import org.eclipse.jet.xpath.Context;
+
+/**
+ * Test the 'descendant-of-self' axis.
+ *
+ */
+public class AncestorOrSelfTests extends AbstractExprTest {
+
+ public void testEvalAsNodeSet_root() {
+ Step stepExpr = new Step(
+ new ContextNode(),
+ Axis.ancestorOrSelf(),
+ NodeTest.allNodes());
+
+ Context context = new Context(document, null);
+
+ Set resultSet = stepExpr.evalAsNodeSet(context);
+
+ assertNotNull(resultSet);
+ assertEquals(1, resultSet.size());
+ assertEquals(document, resultSet.iterator().next());
+ }
+
+ public void testEvalAsNodeSet_rootElement() {
+ Step stepExpr = new Step (
+ new ContextNode(),
+ Axis.ancestorOrSelf(),
+ NodeTest.allNodes());
+
+ Context context = new Context(rootElement, null);
+
+ Set resultSet = stepExpr.evalAsNodeSet(context);
+
+ assertNotNull(resultSet);
+ assertEquals(2, resultSet.size());
+ Iterator i = resultSet.iterator();
+ assertEquals(rootElement, i.next());
+ assertEquals(document, i.next());
+ }
+
+ public void testEvalAsNodeSet_bElement() {
+ Step stepExpr = new Step (
+ new ContextNode(),
+ Axis.ancestorOrSelf(),
+ NodeTest.allNodes());
+
+ Context context = new Context(this.elementB, null);
+
+ Set resultSet = stepExpr.evalAsNodeSet(context);
+
+ assertNotNull(resultSet);
+// assertEquals(4, resultSet.size());
+ Iterator i = resultSet.iterator();
+ assertEquals(elementB, i.next());
+ assertEquals(elementA, i.next());
+ assertEquals(rootElement, i.next());
+ assertEquals(document, i.next());
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AncestorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AncestorTests.java
new file mode 100644
index 0000000..8d97eac
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AncestorTests.java
@@ -0,0 +1,82 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: AncestorTests.java,v 1.1 2008/05/04 23:17:40 pelder Exp $
+ */
+
+package org.eclipse.jet.tests.xpath;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.jet.internal.xpath.ast.Axis;
+import org.eclipse.jet.internal.xpath.ast.ContextNode;
+import org.eclipse.jet.internal.xpath.ast.NodeTest;
+import org.eclipse.jet.internal.xpath.ast.Step;
+import org.eclipse.jet.xpath.Context;
+
+/**
+ * Test the 'descendant-of-self' axis.
+ *
+ */
+public class AncestorTests extends AbstractExprTest {
+
+ public void testEvalAsNodeSet_root() {
+ Step stepExpr = new Step(
+ new ContextNode(),
+ Axis.ancestor(),
+ NodeTest.allNodes());
+
+ Context context = new Context(document, null);
+
+ Set resultSet = stepExpr.evalAsNodeSet(context);
+
+ assertNotNull(resultSet);
+ assertEquals(0, resultSet.size());
+ }
+
+ public void testEvalAsNodeSet_rootElement() {
+ Step stepExpr = new Step (
+ new ContextNode(),
+ Axis.ancestor(),
+ NodeTest.allNodes());
+
+ Context context = new Context(rootElement, null);
+
+ Set resultSet = stepExpr.evalAsNodeSet(context);
+
+ assertNotNull(resultSet);
+ assertEquals(1, resultSet.size());
+ assertEquals(document, resultSet.iterator().next());
+ }
+
+ public void testEvalAsNodeSet_bElement() {
+ Step stepExpr = new Step (
+ new ContextNode(),
+ Axis.ancestor(),
+ NodeTest.allNodes());
+
+ Context context = new Context(this.elementB, null);
+
+ Set resultSet = stepExpr.evalAsNodeSet(context);
+
+ assertNotNull(resultSet);
+// assertEquals(3, resultSet.size());
+ Iterator i = resultSet.iterator();
+ assertEquals(elementA, i.next());
+ assertEquals(rootElement, i.next());
+ assertEquals(document, i.next());
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DescendantTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DescendantTests.java
new file mode 100644
index 0000000..32d29e7
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DescendantTests.java
@@ -0,0 +1,60 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: DescendantTests.java,v 1.1 2008/05/04 23:17:40 pelder Exp $
+ */
+
+package org.eclipse.jet.tests.xpath;
+
+import java.util.Set;
+
+import org.eclipse.jet.internal.xpath.ast.Axis;
+import org.eclipse.jet.internal.xpath.ast.NodeTest;
+import org.eclipse.jet.internal.xpath.ast.Root;
+import org.eclipse.jet.internal.xpath.ast.Step;
+import org.eclipse.jet.xpath.Context;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Test the 'descendant-of-self' axis.
+ *
+ */
+public class DescendantTests extends AbstractExprTest {
+
+ public void testEvalAsNodeSet_root_slash_slash_b() {
+ // /child::root/descendant::b
+ Step stepExpr = new Step(new Step(new Root(), Axis.childAxis(),
+ NodeTest.nameTest(NodeKind.ELEMENT, new ExpandedName("root"))),
+ Axis.descendant(), NodeTest.nameTest(NodeKind.ELEMENT,
+ new ExpandedName("b")));
+ assertEquals("<root>/child::root/descendant::b",stepExpr.toString());
+
+ Context context = new Context(document, null);
+
+ Set resultSet = stepExpr.evalAsNodeSet(context);
+
+ assertNotNull(resultSet);
+ assertEquals(2, resultSet.size());
+ Element elementA2 = (Element) rootElement.getElementsByTagName("a")
+ .item(1);
+ Node elementB2 = (Element) elementA2.getElementsByTagName("b").item(0);
+
+ assertTrue(resultSet.contains(elementB));
+ assertTrue(resultSet.contains(elementB2));
+
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/FollowingSiblingTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/FollowingSiblingTests.java
new file mode 100644
index 0000000..3aa0742
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/FollowingSiblingTests.java
@@ -0,0 +1,79 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.xpath;
+
+import java.util.Iterator;
+
+import org.eclipse.jet.internal.xpath.ast.Axis;
+import org.eclipse.jet.internal.xpath.ast.ContextNode;
+import org.eclipse.jet.internal.xpath.ast.Step;
+import org.eclipse.jet.internal.xpath.ast.NodeTest.NameTest;
+import org.eclipse.jet.xpath.Context;
+import org.eclipse.jet.xpath.NodeSet;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+/**
+ * Test following-sibling axes
+ *
+ */
+public class FollowingSiblingTests extends AbstractExprTest {
+
+ public void testEvalAsNodeSet_ElementA() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.followingSibling(),
+ NameTest.nameTest(NodeKind.ELEMENT, new ExpandedName("a")));
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementA, null));
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Element);
+
+ }
+
+ public void testEvalAsNodeSet_ElementA_all() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.followingSibling(),
+ NameTest.allNodes());
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementA, null));
+
+ assertNotNull(result);
+ assertEquals(3, result.size());
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Text);
+ assertTrue(i.next() instanceof Element);
+ assertTrue(i.next() instanceof Text);
+
+ }
+
+ public void testEvalAsNodeSet_ElementB() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.followingSibling(),
+ NameTest.nameTest(NodeKind.ELEMENT, ExpandedName.ALL));
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementB, null));
+
+ assertNotNull(result);
+ assertEquals(0, result.size());
+
+ }
+ public void testEvalAsNodeSet_ElementB_all() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.followingSibling(),
+ NameTest.allNodes());
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementB, null));
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Text);
+
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/FollowingTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/FollowingTests.java
new file mode 100644
index 0000000..74aee60
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/FollowingTests.java
@@ -0,0 +1,102 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.xpath;
+
+import java.util.Iterator;
+
+import org.eclipse.jet.internal.xpath.ast.Axis;
+import org.eclipse.jet.internal.xpath.ast.ContextNode;
+import org.eclipse.jet.internal.xpath.ast.Step;
+import org.eclipse.jet.internal.xpath.ast.NodeTest.NameTest;
+import org.eclipse.jet.xpath.Context;
+import org.eclipse.jet.xpath.NodeSet;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+/**
+ * Test following-sibling axes
+ *
+ */
+public class FollowingTests extends AbstractExprTest {
+
+ public void testEvalAsNodeSet_ElementA() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.following(),
+ NameTest.nameTest(NodeKind.ELEMENT, new ExpandedName("a")));
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementA, null));
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ Iterator i = result.iterator();
+ Object next1 = i.next();
+ assertTrue(next1 instanceof Element);
+ assertEquals("a",((Element)next1).getNodeName());
+
+ }
+
+ public void testEvalAsNodeSet_ElementA_all() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.following(),
+ NameTest.allNodes());
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementA, null));
+
+ assertNotNull(result);
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Text); //1
+ Element a = (Element)i.next(); //2
+ assertEquals("a", a.getNodeName());
+ assertTrue(i.next() instanceof Text); //3
+ Element b = (Element) i.next(); //4
+ assertEquals("b", b.getNodeName());
+ assertTrue(i.next() instanceof Text); //5
+ assertTrue(i.next() instanceof Text); //6
+ assertTrue(i.next() instanceof Text); //7
+ assertEquals(7, result.size());
+
+ }
+
+ public void testEvalAsNodeSet_ElementB() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.following(),
+ NameTest.nameTest(NodeKind.ELEMENT, ExpandedName.ALL));
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementB, null));
+
+ assertNotNull(result);
+ Iterator i = result.iterator();
+ Element a = (Element) i.next();
+ assertEquals("a", a.getNodeName());
+ Element b = (Element) i.next();
+ assertEquals("b", b.getNodeName());
+ assertEquals(2, result.size());
+
+
+ }
+ public void testEvalAsNodeSet_ElementB_all() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.following(),
+ NameTest.allNodes());
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementB, null));
+
+ assertNotNull(result);
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Text); //1
+ assertTrue(i.next() instanceof Text); //2
+ Element a = (Element)i.next(); //3
+ assertEquals("a", a.getNodeName());
+ assertTrue(i.next() instanceof Text); //4
+ Element b = (Element) i.next(); //5
+ assertEquals("b", b.getNodeName());
+ assertTrue(i.next() instanceof Text); //6
+ assertTrue(i.next() instanceof Text); //7
+ assertTrue(i.next() instanceof Text); //8
+ assertEquals(8, result.size());
+
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/PrecedingSiblingTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/PrecedingSiblingTests.java
new file mode 100644
index 0000000..6422847
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/PrecedingSiblingTests.java
@@ -0,0 +1,76 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.xpath;
+
+import java.util.Iterator;
+
+import org.eclipse.jet.internal.xpath.ast.Axis;
+import org.eclipse.jet.internal.xpath.ast.ContextNode;
+import org.eclipse.jet.internal.xpath.ast.Step;
+import org.eclipse.jet.internal.xpath.ast.NodeTest.NameTest;
+import org.eclipse.jet.xpath.Context;
+import org.eclipse.jet.xpath.NodeSet;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Text;
+
+/**
+ * Test following-sibling axes
+ *
+ */
+public class PrecedingSiblingTests extends AbstractExprTest {
+
+ public void testEvalAsNodeSet_ElementA() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.precedingSibling(),
+ NameTest.nameTest(NodeKind.ELEMENT, new ExpandedName("a")));
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementA, null));
+
+ assertNotNull(result);
+ assertEquals(0, result.size());
+ }
+
+ public void testEvalAsNodeSet_ElementA_all() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.precedingSibling(),
+ NameTest.allNodes());
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementA, null));
+
+ assertNotNull(result);
+ assertEquals(3, result.size());
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Text);
+ assertTrue(i.next() instanceof Comment);
+ assertTrue(i.next() instanceof Text);
+
+ }
+
+ public void testEvalAsNodeSet_ElementB() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.precedingSibling(),
+ NameTest.nameTest(NodeKind.ELEMENT, ExpandedName.ALL));
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementB, null));
+
+ assertNotNull(result);
+ assertEquals(0, result.size());
+
+ }
+ public void testEvalAsNodeSet_ElementB_all() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.precedingSibling(),
+ NameTest.allNodes());
+
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementB, null));
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Text);
+
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/PrecedingTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/PrecedingTests.java
new file mode 100644
index 0000000..610761f
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/PrecedingTests.java
@@ -0,0 +1,116 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.xpath;
+
+import java.util.Iterator;
+
+import org.eclipse.jet.internal.xpath.ast.Axis;
+import org.eclipse.jet.internal.xpath.ast.ContextNode;
+import org.eclipse.jet.internal.xpath.ast.Step;
+import org.eclipse.jet.internal.xpath.ast.NodeTest.NameTest;
+import org.eclipse.jet.xpath.Context;
+import org.eclipse.jet.xpath.NodeSet;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Element;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+
+/**
+ * Test following-sibling axes
+ *
+ */
+public class PrecedingTests extends AbstractExprTest {
+
+ public void testEvalAsNodeSet_ElementA() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.preceding(),
+ NameTest.nameTest(NodeKind.ELEMENT, new ExpandedName("a")));
+
+ Element elementA2 = (Element) rootElement.getElementsByTagName("a").item(1);
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementA2, null));
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ Iterator i = result.iterator();
+ Object next1 = i.next();
+ assertTrue(next1 instanceof Element);
+ assertEquals("a",((Element)next1).getNodeName());
+
+ }
+
+ public void testEvalAsNodeSet_ElementA_all() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.preceding(),
+ NameTest.allNodes());
+
+ Element elementA2 = (Element) rootElement.getElementsByTagName("a").item(1);
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementA2, null));
+
+ assertNotNull(result);
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Text); //1
+ assertTrue(i.next() instanceof Text); //2
+ assertTrue(i.next() instanceof Text); //3
+ Element b = (Element)i.next(); //4
+ assertEquals("b", b.getNodeName());
+ assertTrue(i.next() instanceof Text); //5
+ Element a = (Element)i.next(); //6
+ assertEquals("a", a.getNodeName());
+ assertTrue(i.next() instanceof Text); //7
+ assertTrue(i.next() instanceof Comment); //8
+ assertTrue(i.next() instanceof Text); //9
+ assertTrue(i.next() instanceof ProcessingInstruction); //10
+ assertEquals(10, result.size());
+
+ }
+
+ public void testEvalAsNodeSet_ElementB() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.preceding(),
+ NameTest.nameTest(NodeKind.ELEMENT, ExpandedName.ALL));
+
+ Element elementA2 = (Element) rootElement.getElementsByTagName("a").item(1);
+ Element elementB2 = (Element) elementA2.getElementsByTagName("b").item(0);
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementB2, null));
+
+ assertNotNull(result);
+ Iterator i = result.iterator();
+ Element a = (Element) i.next();
+ assertEquals("b", a.getNodeName());
+ Element b = (Element) i.next();
+ assertEquals("a", b.getNodeName());
+ assertEquals(2, result.size());
+
+
+ }
+ public void testEvalAsNodeSet_ElementB_all() {
+ final Step stepExpr = new Step(new ContextNode(),
+ Axis.preceding(),
+ NameTest.allNodes());
+
+ Element elementA2 = (Element) rootElement.getElementsByTagName("a").item(1);
+ Element elementB2 = (Element) elementA2.getElementsByTagName("b").item(0);
+ final NodeSet result = stepExpr.evalAsNodeSet(new Context(elementB2, null));
+
+ assertNotNull(result);
+ Iterator i = result.iterator();
+ assertTrue(i.next() instanceof Text); //1
+ assertTrue(i.next() instanceof Text); //2
+ assertTrue(i.next() instanceof Text); //3
+ assertTrue(i.next() instanceof Text); //4
+ Element b = (Element)i.next(); //5
+ assertEquals("b", b.getNodeName());
+ assertTrue(i.next() instanceof Text); //6
+ Element a = (Element)i.next(); //7
+ assertEquals("a", a.getNodeName());
+ assertTrue(i.next() instanceof Text); //8
+ assertTrue(i.next() instanceof Comment); //9
+ assertTrue(i.next() instanceof Text); //10
+ assertTrue(i.next() instanceof ProcessingInstruction); //11
+ assertEquals(11, result.size());
+
+ }
+}

Back to the top