1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jxpath.ri.compiler;
17
18 import org.apache.commons.jxpath.JXPathTestCase;
19 import org.apache.commons.jxpath.ri.Parser;
20
21 /***
22 * Tests the determination of whether an expression is context dependent.
23 *
24 * @author Dmitri Plotnikov
25 * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:42 $
26 */
27
28 public class ContextDependencyTest extends JXPathTestCase {
29 public ContextDependencyTest(String name) {
30 super(name);
31 }
32
33 public void testContextDependency() {
34 testContextDependency("1", false);
35 testContextDependency("$x", false);
36 testContextDependency("/foo", false);
37 testContextDependency("foo", true);
38 testContextDependency("/foo[3]", false);
39 testContextDependency("/foo[$x]", false);
40 testContextDependency("/foo[bar]", true);
41 testContextDependency("3 + 5", false);
42 testContextDependency("test:func(3, 5)", true);
43 testContextDependency("test:func(3, foo)", true);
44 }
45
46 public void testContextDependency(String xpath, boolean expected) {
47 Expression expr =
48 (Expression) Parser.parseExpression(xpath, new TreeCompiler());
49
50 assertEquals(
51 "Context dependency <" + xpath + ">",
52 expected,
53 expr.isContextDependent());
54 }
55 }