1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jxpath.ri.compiler;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21
22 import org.apache.commons.jxpath.AbstractJXPathTest;
23 import org.apache.commons.jxpath.ri.Parser;
24 import org.junit.jupiter.api.Test;
25
26
27
28
29 public class ContextDependencyTest extends AbstractJXPathTest {
30
31 @Test
32 public void testContextDependency() {
33 testContextDependency("1", false);
34 testContextDependency("$x", false);
35 testContextDependency("/foo", false);
36 testContextDependency("foo", true);
37 testContextDependency("/foo[3]", false);
38 testContextDependency("/foo[$x]", false);
39 testContextDependency("/foo[bar]", true);
40 testContextDependency("3 + 5", false);
41 testContextDependency("test:func(3, 5)", true);
42 testContextDependency("test:func(3, foo)", true);
43 }
44
45 public void testContextDependency(final String xpath, final boolean expected) {
46 final Expression expr = (Expression) Parser.parseExpression(xpath, new TreeCompiler());
47 assertEquals(expected, expr.isContextDependent(), "Context dependency <" + xpath + ">");
48 }
49 }