commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r552591 - in /jakarta/commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/model/NodePointer.java test/org/apache/commons/jxpath/ri/compiler/VariableTest.java
Date Mon, 02 Jul 2007 20:47:48 GMT
Author: mbenson
Date: Mon Jul  2 13:47:47 2007
New Revision: 552591

URL: http://svn.apache.org/viewvc?view=rev&rev=552591
Log:
[JXPATH-89] relax restriction against comparisons between different trees; incompatible parents
are simply equal (thus no assumptions can be made wrt order).

Modified:
    jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
    jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/VariableTest.java

Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java?view=diff&rev=552591&r1=552590&r2=552591
==============================================================================
--- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
(original)
+++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
Mon Jul  2 13:47:47 2007
@@ -662,9 +662,7 @@
         }
 
         if (depth1 == 1) {
-            throw new JXPathException(
-                    "Cannot compare pointers that do not belong to the same tree: '"
-                            + p1 + "' and '" + p2 + "'");
+            return 0;
         }
         int r = compareNodePointers(p1.parent, depth1 - 1, p2.parent, depth2 - 1);
         if (r != 0) {

Modified: jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/VariableTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/VariableTest.java?view=diff&rev=552591&r1=552590&r2=552591
==============================================================================
--- jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/VariableTest.java
(original)
+++ jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/VariableTest.java
Mon Jul  2 13:47:47 2007
@@ -16,9 +16,16 @@
  */
 package org.apache.commons.jxpath.ri.compiler;
 
+import java.io.StringReader;
+import java.util.Iterator;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathTestCase;
 import org.apache.commons.jxpath.Variables;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
 
 /**
  * Test basic functionality of JXPath - infoset types,
@@ -84,7 +91,7 @@
         assertTrue(
             "Evaluating '$none', expected exception - did not get it",
             exception);
-
+        
         exception = false;
         try {
             context.setValue("$none", new Integer(1));
@@ -265,5 +272,20 @@
             "Remove collection element",
             "temp2",
             context.getValue("$temp[1]"));
+    }
+    
+    public void testUnionOfVariableAndNode() throws Exception {
+        Document doc = DocumentBuilderFactory.newInstance()
+                .newDocumentBuilder().parse(
+                        new InputSource(new StringReader(
+                                "<MAIN><A/><A/></MAIN>")));
+
+        JXPathContext context = JXPathContext.newContext(doc);
+        context.getVariables().declareVariable("var", "varValue");
+        int sz = 0;
+        for (Iterator ptrs = context.iteratePointers("$var | /MAIN/A"); ptrs.hasNext(); sz++)
{
+            ptrs.next();
+        }
+        assertEquals(3, sz);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message