commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/digester/src/test/org/apache/commons/digester EBRTestCase.java
Date Mon, 09 Feb 2004 20:30:35 GMT
rdonkin     2004/02/09 12:30:35

  Modified:    digester/src/java/org/apache/commons/digester
                        ExtendedBaseRules.java
               digester/src/test/org/apache/commons/digester
                        EBRTestCase.java
  Log:
  Fixed a bug in extended rules set.
  
  Revision  Changes    Path
  1.11      +24 -10    jakarta-commons/digester/src/java/org/apache/commons/digester/ExtendedBaseRules.java
  
  Index: ExtendedBaseRules.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/ExtendedBaseRules.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ExtendedBaseRules.java	10 Jan 2004 17:34:18 -0000	1.10
  +++ ExtendedBaseRules.java	9 Feb 2004 20:30:34 -0000	1.11
  @@ -327,13 +327,27 @@
   
                   } else if (key.endsWith("/*")) {
                       // check for ancester match
  -                    int patternStart = 0;
                       if (key.startsWith("*/")) {
  -                        patternStart = 2;
  -                    }
  -                    ancesterMatched = 
  -                        (pattern.lastIndexOf(key.substring(patternStart, key.length() -
2)) > -1);
  -                                    
  +                        String patternBody = key.substring(2, key.length() - 2);
  +                        if (pattern.endsWith(patternBody)) {
  +                            ancesterMatched = true;
  +                        } else {
  +                            ancesterMatched = (pattern.indexOf(patternBody + "/") >
-1);
  +                        }
  +                    } else {
  +                        String bodyPattern = key.substring(0, key.length() - 2);
  +                        if (pattern.startsWith(bodyPattern))
  +                        {
  +                            if (pattern.length() == bodyPattern.length()) {
  +                                // exact match
  +                                ancesterMatched = true;
  +                            } else {
  +                                ancesterMatched = ( pattern.charAt(bodyPattern.length())
== '/' );
  +                            }
  +                        } else {
  +                            ancesterMatched = false;  
  +                        } 
  +                    }               
                   } else {
                       // try for a base match
                       basicMatched = basicMatch(key, pattern);
  
  
  
  1.12      +26 -4     jakarta-commons/digester/src/test/org/apache/commons/digester/EBRTestCase.java
  
  Index: EBRTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/EBRTestCase.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- EBRTestCase.java	18 Oct 2003 13:30:22 -0000	1.11
  +++ EBRTestCase.java	9 Feb 2004 20:30:34 -0000	1.12
  @@ -467,4 +467,26 @@
           list = digester.getRules().match(null, "a/b/c/d");
           assertEquals("Long match (4)", 0, list.size());
       }
  +    
  +    public void testInstructors() {
  +        digester.getRules().clear();
  +        
  +        digester.addRule("!instructors/*", new TestRule("instructors"));
  +        digester.addRule("!instructor/*", new TestRule("instructor"));
  +        
  +        List list = digester.getRules().match(null, "instructors");
  +        assertEquals("Only expect to match instructors", 1, list.size());
  +        assertEquals("Instructors expected", "instructors" , ((TestRule) list.get(0)).getIdentifier());

  +
  +    }
  +    
  +    public void testMiddleInstructors() {
  +        digester.getRules().clear();
  +        
  +        digester.addRule("!instructors/*", new TestRule("instructors"));
  +        
  +        List list = digester.getRules().match(null, "/tosh/instructors/fiddlesticks");
  +        assertEquals("No matches expected", 0, list.size());
  +
  +    }
   }
  
  
  

---------------------------------------------------------------------
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