Skip to content

Commit

Permalink
Add more testing to CompareChildToAbsoluteExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Oct 4, 2023
1 parent d444802 commit 8770307
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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[]{
Expand Down

0 comments on commit 8770307

Please sign in to comment.