summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-07-12 09:39:49 (EDT)
committerpelder2007-07-12 09:39:49 (EDT)
commit07b0694a78bfb41f0f056b6bb12c418a61c90a07 (patch)
treecb620cdd26aa93ba3dab51310d29570dbd60c0e9
parent97ec7abe0666d3cdb4e759244c2ca7c6cc5a167b (diff)
downloadorg.eclipse.jet-07b0694a78bfb41f0f056b6bb12c418a61c90a07.zip
org.eclipse.jet-07b0694a78bfb41f0f056b6bb12c418a61c90a07.tar.gz
org.eclipse.jet-07b0694a78bfb41f0f056b6bb12c418a61c90a07.tar.bz2
[196294] XPath <= and >= are actually implemented as < and >
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/ast/RelOp.java15
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/RelOpTests.java234
2 files changed, 208 insertions, 41 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/ast/RelOp.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/ast/RelOp.java
index c8f3bfe..8439832 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/ast/RelOp.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/ast/RelOp.java
@@ -1,7 +1,5 @@
/**
- * <copyright>
- *
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 2007 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
@@ -10,9 +8,6 @@
* Contributors:
* IBM - Initial API and implementation
*
- * </copyright>
- *
- * $Id$
*/
package org.eclipse.jet.internal.xpath.ast;
@@ -109,11 +104,11 @@ public abstract class RelOp extends BooleanExpr
}
};
- private static final ITest lessThenOrEqualTest = new RelativeTest()
+ private static final ITest lessThanOrEqualTest = new RelativeTest()
{
public boolean test(Number n, Object o)
{
- return n.doubleValue() < NumberFunction.evaluate(o);
+ return n.doubleValue() <= NumberFunction.evaluate(o);
}
};
@@ -170,7 +165,7 @@ public abstract class RelOp extends BooleanExpr
public Lte(ExprNode left, ExprNode right)
{
- super(left, right, lessThenOrEqualTest);
+ super(left, right, lessThanOrEqualTest);
}
public String opName()
@@ -207,7 +202,7 @@ public abstract class RelOp extends BooleanExpr
public Gte(ExprNode left, ExprNode right)
{
// Reversal of left and right is intensional!
- super(right, left, lessThenOrEqualTest);
+ super(right, left, lessThanOrEqualTest);
}
public String opName()
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/RelOpTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/RelOpTests.java
index d4761af..4890b36 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/RelOpTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/RelOpTests.java
@@ -1,3 +1,14 @@
+/**
+ * Copyright (c) 2006, 2007 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
+ *
+ */
package org.eclipse.jet.tests.xpath;
import org.eclipse.jet.internal.xpath.NodeSetImpl;
@@ -13,53 +24,53 @@ public class RelOpTests extends AbstractExprTest {
public void testEquals_Number_Number() {
BooleanExpr expr = new RelOp.Eq(new NumberLiteral(3), new NumberLiteral(3));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NumberLiteral(3), new NumberLiteral(3.0001));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NumberLiteral(Double.NaN), new NumberLiteral(Double.NaN));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NumberLiteral(Double.POSITIVE_INFINITY), new NumberLiteral(Double.POSITIVE_INFINITY));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NumberLiteral(Double.NEGATIVE_INFINITY), new NumberLiteral(Double.NEGATIVE_INFINITY));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NumberLiteral(Double.POSITIVE_INFINITY), new NumberLiteral(Double.NEGATIVE_INFINITY));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
}
public void testEquals_String_String() {
BooleanExpr expr = new RelOp.Eq(new StringLiteral("hello"), new StringLiteral("hello"));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new StringLiteral("hello"), new StringLiteral("world"));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new StringLiteral("hello"), new StringLiteral("hello4"));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new StringLiteral(""), new StringLiteral(""));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new StringLiteral("hello"), new StringLiteral(""));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
}
public void testEquals_Boolean_Boolean() {
BooleanExpr expr = new RelOp.Eq(BooleanLiteral.TRUE, BooleanLiteral.TRUE);
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(BooleanLiteral.FALSE, BooleanLiteral.FALSE);
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(BooleanLiteral.FALSE, BooleanLiteral.TRUE);
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(BooleanLiteral.TRUE, BooleanLiteral.FALSE);
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
}
public void testEquals_Nodeset_Nodeset() {
@@ -79,19 +90,19 @@ public class RelOpTests extends AbstractExprTest {
// comparing to an empty node set already returns false. See http://www.w3.org/TR/xpath#booleans
BooleanExpr expr = new RelOp.Eq(new NodeSetLiteral(empty1), new NodeSetLiteral(empty2));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NodeSetLiteral(singleA), new NodeSetLiteral(empty1));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NodeSetLiteral(empty1), new NodeSetLiteral(singleA));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NodeSetLiteral(singleA), new NodeSetLiteral(singleA2));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NodeSetLiteral(ab), new NodeSetLiteral(ba));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
}
public void testEquals_Nodeset_String() {
@@ -106,19 +117,19 @@ public class RelOpTests extends AbstractExprTest {
ba.add(elementA);
BooleanExpr expr = new RelOp.Eq(new NodeSetLiteral(empty1), new StringLiteral(""));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NodeSetLiteral(empty1), new StringLiteral("foo"));
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NodeSetLiteral(singleA), new StringLiteral(EXPECTED_A_TEXT));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NodeSetLiteral(ab), new StringLiteral(EXPECTED_A_TEXT));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NodeSetLiteral(ba), new StringLiteral(EXPECTED_A_TEXT));
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
}
@@ -134,23 +145,184 @@ public class RelOpTests extends AbstractExprTest {
ba.add(elementA);
BooleanExpr expr = new RelOp.Eq(new NodeSetLiteral(empty1), BooleanLiteral.TRUE);
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NodeSetLiteral(empty1), BooleanLiteral.FALSE);
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NodeSetLiteral(singleA), BooleanLiteral.TRUE);
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NodeSetLiteral(singleA), BooleanLiteral.FALSE);
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
expr = new RelOp.Eq(new NodeSetLiteral(ab), BooleanLiteral.TRUE);
- assertTrue(expr.evalAsBoolean(null));
+ assertTrue(expr);
expr = new RelOp.Eq(new NodeSetLiteral(ba), BooleanLiteral.FALSE);
- assertFalse(expr.evalAsBoolean(null));
+ assertFalse(expr);
}
+ public void testGT_Number_Number() {
+ final NumberLiteral n_3 = new NumberLiteral(3);
+ final NumberLiteral n_3_0001 = new NumberLiteral(3.0001);
+ final NumberLiteral n_pos_infinity = new NumberLiteral(Double.POSITIVE_INFINITY);
+ final NumberLiteral n_neg_infinity = new NumberLiteral(Double.NEGATIVE_INFINITY);
+ final NumberLiteral n_nan = new NumberLiteral(Double.NaN);
+
+ assertFalse(new RelOp.Gt(n_3, n_3));
+
+ assertFalse(new RelOp.Gt(n_3, n_3_0001));
+
+ assertTrue(new RelOp.Gt(n_3_0001, n_3));
+
+ assertFalse(new RelOp.Gt(n_nan, n_nan));
+
+ assertFalse(new RelOp.Gt(n_3, n_nan));
+
+ assertFalse(new RelOp.Gt(n_nan, n_3));
+
+ assertFalse(new RelOp.Gt(n_3, n_pos_infinity));
+
+ assertTrue(new RelOp.Gt(n_pos_infinity, n_3));
+
+ assertFalse(new RelOp.Gt(n_neg_infinity, n_3));
+
+ assertTrue(new RelOp.Gt(n_3, n_neg_infinity));
+
+ assertFalse(new RelOp.Gt(n_pos_infinity, n_pos_infinity));
+
+ assertFalse(new RelOp.Gt(n_neg_infinity, n_neg_infinity));
+
+ assertTrue(new RelOp.Gt(n_pos_infinity, n_neg_infinity));
+
+ assertFalse(new RelOp.Gt(n_neg_infinity, n_pos_infinity));
+
+ }
+
+ public void testGTE_Number_Number() {
+ final NumberLiteral n_3 = new NumberLiteral(3);
+ final NumberLiteral n_3_0001 = new NumberLiteral(3.0001);
+ final NumberLiteral n_pos_infinity = new NumberLiteral(Double.POSITIVE_INFINITY);
+ final NumberLiteral n_neg_infinity = new NumberLiteral(Double.NEGATIVE_INFINITY);
+ final NumberLiteral n_nan = new NumberLiteral(Double.NaN);
+
+ assertTrue(new RelOp.Gte(n_3, n_3));
+
+ assertFalse(new RelOp.Gte(n_3, n_3_0001));
+
+ assertTrue(new RelOp.Gte(n_3_0001, n_3));
+
+ assertFalse(new RelOp.Gte(n_nan, n_nan));
+
+ assertFalse(new RelOp.Gte(n_3, n_nan));
+
+ assertFalse(new RelOp.Gte(n_nan, n_3));
+
+ assertFalse(new RelOp.Gte(n_3, n_pos_infinity));
+
+ assertTrue(new RelOp.Gte(n_pos_infinity, n_3));
+
+ assertFalse(new RelOp.Gte(n_neg_infinity, n_3));
+
+ assertTrue(new RelOp.Gte(n_3, n_neg_infinity));
+
+ assertTrue(new RelOp.Gte(n_pos_infinity, n_pos_infinity));
+
+ assertTrue(new RelOp.Gte(n_neg_infinity, n_neg_infinity));
+
+ assertTrue(new RelOp.Gte(n_pos_infinity, n_neg_infinity));
+
+ assertFalse(new RelOp.Gte(n_neg_infinity, n_pos_infinity));
+
+ }
+
+ public void testLT_Number_Number() {
+ final NumberLiteral n_3 = new NumberLiteral(3);
+ final NumberLiteral n_3_0001 = new NumberLiteral(3.0001);
+ final NumberLiteral n_pos_infinity = new NumberLiteral(Double.POSITIVE_INFINITY);
+ final NumberLiteral n_neg_infinity = new NumberLiteral(Double.NEGATIVE_INFINITY);
+ final NumberLiteral n_nan = new NumberLiteral(Double.NaN);
+
+ assertFalse(new RelOp.Lt(n_3, n_3));
+
+ assertTrue(new RelOp.Lt(n_3, n_3_0001));
+
+ assertFalse(new RelOp.Lt(n_3_0001, n_3));
+
+ assertFalse(new RelOp.Lt(n_nan, n_nan));
+
+ assertFalse(new RelOp.Lt(n_3, n_nan));
+
+ assertFalse(new RelOp.Lt(n_nan, n_3));
+
+ assertTrue(new RelOp.Lt(n_3, n_pos_infinity));
+
+ assertFalse(new RelOp.Lt(n_pos_infinity, n_3));
+
+ assertTrue(new RelOp.Lt(n_neg_infinity, n_3));
+
+ assertFalse(new RelOp.Lt(n_3, n_neg_infinity));
+
+ assertFalse(new RelOp.Lt(n_pos_infinity, n_pos_infinity));
+
+ assertFalse(new RelOp.Lt(n_neg_infinity, n_neg_infinity));
+
+ assertFalse(new RelOp.Lt(n_pos_infinity, n_neg_infinity));
+
+ assertTrue(new RelOp.Lt(n_neg_infinity, n_pos_infinity));
+
+ }
+
+ public void testLTE_Number_Number() {
+ final NumberLiteral n_3 = new NumberLiteral(3);
+ final NumberLiteral n_3_0001 = new NumberLiteral(3.0001);
+ final NumberLiteral n_pos_infinity = new NumberLiteral(Double.POSITIVE_INFINITY);
+ final NumberLiteral n_neg_infinity = new NumberLiteral(Double.NEGATIVE_INFINITY);
+ final NumberLiteral n_nan = new NumberLiteral(Double.NaN);
+
+ assertTrue(new RelOp.Lte(n_3, n_3));
+
+ assertTrue(new RelOp.Lte(n_3, n_3_0001));
+
+ assertFalse(new RelOp.Lte(n_3_0001, n_3));
+
+ assertFalse(new RelOp.Lte(n_nan, n_nan));
+
+ assertFalse(new RelOp.Lte(n_3, n_nan));
+
+ assertFalse(new RelOp.Lte(n_nan, n_3));
+
+ assertTrue(new RelOp.Lte(n_3, n_pos_infinity));
+
+ assertFalse(new RelOp.Lte(n_pos_infinity, n_3));
+
+ assertTrue(new RelOp.Lte(n_neg_infinity, n_3));
+
+ assertFalse(new RelOp.Lte(n_3, n_neg_infinity));
+
+ assertTrue(new RelOp.Lte(n_pos_infinity, n_pos_infinity));
+
+ assertTrue(new RelOp.Lte(n_neg_infinity, n_neg_infinity));
+
+ assertFalse(new RelOp.Lte(n_pos_infinity, n_neg_infinity));
+
+ assertTrue(new RelOp.Lte(n_neg_infinity, n_pos_infinity));
+
+ }
+
+ /**
+ * @param expr
+ */
+ private void assertTrue(BooleanExpr expr) {
+ assertTrue(expr.evalAsBoolean(null));
+ }
+
+ /**
+ * @param expr
+ */
+ private void assertFalse(BooleanExpr expr) {
+ assertFalse(expr.evalAsBoolean(null));
+ }
}