dmitri      2004/01/16 19:25:14

  Modified:    jxpath/src/test/org/apache/commons/jxpath/ri/model
                        BeanModelTestCase.java XMLModelTestCase.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/dom
                        DOMNodeIterator.java
  Log:
  Fixed a bug in DOMNodeIterator.previous(), which caused the function last() to fail.
  
  Revision  Changes    Path
  1.16      +19 -7     
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java
  
  Index: BeanModelTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- BeanModelTestCase.java    9 Oct 2003 21:31:43 -0000       1.15
  +++ BeanModelTestCase.java    17 Jan 2004 03:25:14 -0000      1.16
  @@ -99,11 +99,11 @@
       }
   
       public void setUp() {
  -        if (context == null) {
  +//        if (context == null) {
               context = JXPathContext.newContext(createContextBean());
               context.setLocale(Locale.US);
               context.setFactory(getAbstractFactory());
  -        }
  +//        }
       }
   
       protected abstract Object createContextBean();
  @@ -673,7 +673,19 @@
               "boolean(integers[position() > 4])",
               Boolean.FALSE);
   
  -        assertXPathValue(context, "sum(integers)", new Double(10));
  +        assertXPathValue(context, "sum(integers)", new Double(10));        
  +
  +        assertXPathValueAndPointer(
  +                context,
  +                "integers[last()]",
  +                new Integer(4),
  +                "/integers[4]");
  +
  +        assertXPathValueAndPointer(
  +                context,
  +                "//strings[last()]",
  +                "String 3",
  +                "/beans[1]/strings[3]");
       }
   
       public void testBooleanPredicate() {
  
  
  
  1.14      +14 -7     
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
  
  Index: XMLModelTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XMLModelTestCase.java     9 Oct 2003 21:31:43 -0000       1.13
  +++ XMLModelTestCase.java     17 Jan 2004 03:25:14 -0000      1.14
  @@ -108,10 +108,10 @@
   
       protected DocumentContainer createDocumentContainer() {
           return new DocumentContainer(
  -            JXPathTestCase.class.getResource("Vendor.xml"),
  -            getModel());
  +                JXPathTestCase.class.getResource("Vendor.xml"),
  +                getModel());
       }
  -
  +    
       protected abstract AbstractFactory getAbstractFactory();
   
       protected JXPathContext createContext() {
  @@ -759,5 +759,12 @@
               context,
               "boolean(vendor//promotion[../@stores = 'some'])",
               Boolean.FALSE);
  +    }
  +    
  +    public void testFunctionsLastAndPosition() {
  +        assertXPathPointer(
  +                context,
  +                "vendor//location[last()]",
  +                "/vendor[1]/location[2]");
       }
   }
  
  
  
  1.9       +17 -10    
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java
  
  Index: DOMNodeIterator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodeIterator.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DOMNodeIterator.java      9 Oct 2003 21:31:41 -0000       1.8
  +++ DOMNodeIterator.java      17 Jan 2004 03:25:14 -0000      1.9
  @@ -97,13 +97,12 @@
       }
   
       public NodePointer getNodePointer() {
  +        if (position == 0) {
  +            setPosition(1);
  +        }
           if (child == null) {
  -            if (!setPosition(1)) {
  -                return null;
  -            }
  -            position = 0;
  +            return null;
           }
  -
           return new DOMNodePointer(parent, child);
       }
   
  @@ -128,7 +127,15 @@
       private boolean previous() {
           position--;
           if (!reverse) {
  -            child = child.getPreviousSibling();
  +            if (position == 0) {
  +                child = null;
  +            }
  +            else if (child == null) {
  +                child = node.getLastChild();
  +            }
  +            else {
  +                child = child.getPreviousSibling();
  +            }
               while (child != null && !testChild()) {
                   child = child.getPreviousSibling();
               }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to