1 16 package org.apache.commons.jxpath.ri.compiler; 17 18 import org.apache.commons.jxpath.JXPathContext; 19 import org.apache.commons.jxpath.JXPathTestCase; 20 import org.apache.commons.jxpath.Variables; 21 22 29 30 public class CoreOperationTest extends JXPathTestCase { 31 private JXPathContext context; 32 33 38 public CoreOperationTest(String name) { 39 super(name); 40 } 41 42 public void setUp() { 43 if (context == null) { 44 context = JXPathContext.newContext(null); 45 Variables vars = context.getVariables(); 46 vars.declareVariable("integer", new Integer (1)); 47 } 48 } 49 50 public void testInfoSetTypes() { 51 52 assertXPathValue(context, "1", new Double (1.0)); 54 assertXPathPointer(context, "1", "1"); 55 assertXPathValueIterator(context, "1", list(new Double (1.0))); 56 57 assertXPathPointerIterator(context, "1", list("1")); 58 59 assertXPathValue(context, "-1", new Double (-1.0)); 60 assertXPathValue(context, "2 + 2", new Double (4.0)); 61 assertXPathValue(context, "3 - 2", new Double (1.0)); 62 assertXPathValue(context, "1 + 2 + 3 - 4 + 5", new Double (7.0)); 63 assertXPathValue(context, "3 * 2", new Double (3.0 * 2.0)); 64 assertXPathValue(context, "3 div 2", new Double (3.0 / 2.0)); 65 assertXPathValue(context, "5 mod 2", new Double (1.0)); 66 67 assertXPathValue(context, "5.9 mod 2.1", new Double (1.0)); 69 70 assertXPathValue(context, "5 mod -2", new Double (1.0)); 71 assertXPathValue(context, "-5 mod 2", new Double (-1.0)); 72 assertXPathValue(context, "-5 mod -2", new Double (-1.0)); 73 assertXPathValue(context, "1 < 2", Boolean.TRUE); 74 assertXPathValue(context, "1 > 2", Boolean.FALSE); 75 assertXPathValue(context, "1 <= 1", Boolean.TRUE); 76 assertXPathValue(context, "1 >= 2", Boolean.FALSE); 77 assertXPathValue(context, "3 > 2 > 1", Boolean.FALSE); 78 assertXPathValue(context, "3 > 2 and 2 > 1", Boolean.TRUE); 79 assertXPathValue(context, "3 > 2 and 2 < 1", Boolean.FALSE); 80 assertXPathValue(context, "3 < 2 or 2 > 1", Boolean.TRUE); 81 assertXPathValue(context, "3 < 2 or 2 < 1", Boolean.FALSE); 82 assertXPathValue(context, "1 = 1", Boolean.TRUE); 83 assertXPathValue(context, "1 = '1'", Boolean.TRUE); 84 assertXPathValue(context, "1 > 2 = 2 > 3", Boolean.TRUE); 85 assertXPathValue(context, "1 > 2 = 0", Boolean.TRUE); 86 assertXPathValue(context, "1 = 2", Boolean.FALSE); 87 88 assertXPathValue(context, "$integer", new Double (1), Double .class); 89 90 assertXPathValue(context, "2 + 3", "5.0", String .class); 91 92 assertXPathValue(context, "2 + 3", Boolean.TRUE, boolean.class); 93 94 assertXPathValue(context, "'true'", Boolean.TRUE, Boolean .class); 95 } 96 } | Popular Tags |