diff --git a/src/test/java/org/javarosa/core/model/CompareChildToAbsoluteExpressionTest.java b/src/test/java/org/javarosa/core/model/CompareChildToAbsoluteExpressionTest.java index 959fb861b..67f61e57f 100644 --- a/src/test/java/org/javarosa/core/model/CompareChildToAbsoluteExpressionTest.java +++ b/src/test/java/org/javarosa/core/model/CompareChildToAbsoluteExpressionTest.java @@ -2,6 +2,7 @@ import org.javarosa.xpath.expr.XPathEqExpr; import org.javarosa.xpath.expr.XPathExpression; +import org.javarosa.xpath.expr.XPathFilterExpr; import org.javarosa.xpath.expr.XPathFuncExpr; import org.javarosa.xpath.expr.XPathNumericLiteral; import org.javarosa.xpath.expr.XPathPathExpr; @@ -19,6 +20,22 @@ public class CompareChildToAbsoluteExpressionTest { + @Test + public void parse_doesNotParseExpressionsWhereBothSidesAreRelative() { + XPathEqExpr expression = new XPathEqExpr( + true, + new XPathPathExpr(XPathPathExpr.INIT_CONTEXT_RELATIVE, new XPathStep[]{ + new XPathStep(XPathStep.AXIS_CHILD, new XPathQName("name")) } + ), + new XPathPathExpr(XPathPathExpr.INIT_CONTEXT_RELATIVE, new XPathStep[]{ + new XPathStep(XPathStep.AXIS_CHILD, new XPathQName("name")) } + ) + ); + + CompareChildToAbsoluteExpression parsed = CompareChildToAbsoluteExpression.parse(expression); + assertThat(parsed, nullValue()); + } + @Test public void parse_parsesStringLiteralAsAbsolute() { XPathEqExpr expression = new XPathEqExpr( @@ -90,6 +107,25 @@ public void parse_doesNotParseNonIdempotentFunction() { assertThat(parsed, nullValue()); } + @Test + public void parse_parsesContextRelativeExpressionsAsAbsolute() { + XPathEqExpr expression = new XPathEqExpr( + true, + new XPathPathExpr(XPathPathExpr.INIT_CONTEXT_RELATIVE, new XPathStep[]{ + new XPathStep(XPathStep.AXIS_CHILD, new XPathQName("name")) } + ), + new XPathPathExpr( + new XPathFilterExpr(new XPathFuncExpr(new XPathQName("blah"), new XPathExpression[0]), new XPathExpression[0]), + new XPathStep[0] + ) + ); + + CompareChildToAbsoluteExpression parsed = CompareChildToAbsoluteExpression.parse(expression); + assertThat(parsed, not(nullValue())); + assertThat(parsed.getRelativeSide(), equalTo(expression.a)); + assertThat(parsed.getAbsoluteSide(), equalTo(expression.b)); + } + @Test public void parse_parsesRelativeAndAbsoluteRegardlessOfSide() { XPathPathExpr relative = new XPathPathExpr(XPathPathExpr.INIT_CONTEXT_RELATIVE, new XPathStep[]{