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 RuleTestCase.java RulesBaseTestCase.java TestRuleSet.java
Date Wed, 10 Jul 2002 18:12:34 GMT
rdonkin     2002/07/10 11:12:34

  Modified:    digester/src/java/org/apache/commons/digester
                        ExtendedBaseRules.java RulesBase.java
               digester/src/test/org/apache/commons/digester
                        EBRTestCase.java RuleTestCase.java
                        RulesBaseTestCase.java TestRuleSet.java
  Log:
  Applied patch supplied by Mike Flester. This fixes a bug in the rules implementations which
meant that root tail matches were missed. Also added unit tests for the bug.
  
  Revision  Changes    Path
  1.3       +6 -5      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExtendedBaseRules.java	9 Jan 2002 20:22:49 -0000	1.2
  +++ ExtendedBaseRules.java	10 Jul 2002 18:12:33 -0000	1.3
  @@ -405,7 +405,8 @@
        * Matches the end of the pattern to the key.
        */
       private boolean basicMatch(String key, String pattern) {
  -        return pattern.endsWith(key.substring(1));
  +        return (pattern.equals(key.substring(2)) ||
  +                pattern.endsWith(key.substring(1)));
       }
   
   }
  
  
  
  1.8       +6 -5      jakarta-commons/digester/src/java/org/apache/commons/digester/RulesBase.java
  
  Index: RulesBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/RulesBase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RulesBase.java	9 Jan 2002 20:22:49 -0000	1.7
  +++ RulesBase.java	10 Jul 2002 18:12:33 -0000	1.8
  @@ -252,7 +252,8 @@
               while (keys.hasNext()) {
                   String key = (String) keys.next();
                   if (key.startsWith("*/")) {
  -                    if (pattern.endsWith(key.substring(1))) {
  +                    if (pattern.equals(key.substring(2)) ||
  +                        pattern.endsWith(key.substring(1))) {
                           if (key.length() > longKey.length()) {
                               // rulesList = (List) this.cache.get(key);
                               rulesList = lookup(namespaceURI, key);
  
  
  
  1.5       +56 -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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EBRTestCase.java	23 Mar 2002 17:45:59 -0000	1.4
  +++ EBRTestCase.java	10 Jul 2002 18:12:33 -0000	1.5
  @@ -332,4 +332,56 @@
           digester.getRules().clear();
   
       }
  +    
  +    
  +
  +    /**
  +     * Basic test of wild matches.
  +     * A universal will match matches anything!
  +     * A non-universal will match matches anything not matched by something else.
  +     * This method tests non-universal and universal wild matches.
  +     */
  +    public void testRootTailMatch() {
  +
  +        // clear any existing rules
  +        digester.getRules().clear();
  +
  +        assertEquals("Initial rules list is empty",
  +                0, digester.getRules().rules().size());
  +
  +        // Set up rules
  +        // The combinations a little large to test everything but we'll pick a couple and
try them.
  +        digester.addRule("*/a", new TestRule("a_tail"));
  +
  +
  +        List list = null;
  +        Iterator it = null;
  +
  +        list = digester.getRules().match(null, "a");
  +
  +        assertEquals("Testing tail wrong size (A)", 1, list.size());
  +        assertEquals("Testing tail mismatch (B)", "a_tail", ((TestRule) list.get(0)).getIdentifier());
  +
  +
  +        list = digester.getRules().match(null, "beta/a");
  +
  +        assertEquals("Testing tail wrong size (C)", 1, list.size());
  +        assertEquals("Testing tail mismatch (D)", "a_tail", ((TestRule) list.get(0)).getIdentifier());
  +
  +        list = digester.getRules().match(null, "be/aaa");
  +
  +        assertEquals("Testing tail no matches (E)", 0, list.size());
  +        
  +        list = digester.getRules().match(null, "aaa");
  +
  +        assertEquals("Testing tail no matches (F)", 0, list.size());
  +        
  +        list = digester.getRules().match(null, "a/beta");
  +
  +        assertEquals("Testing tail no matches (G)", 0, list.size());
  +
  +        // clean up
  +        digester.getRules().clear();
  +
  +    }
   }
  
  
  
  1.16      +5 -6      jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java
  
  Index: RuleTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- RuleTestCase.java	8 Jul 2002 21:25:30 -0000	1.15
  +++ RuleTestCase.java	10 Jul 2002 18:12:33 -0000	1.16
  @@ -696,8 +696,7 @@
           }
           */
       }
  -
  -
  +    
       // ------------------------------------------------ Utility Support Methods
   
   
  
  
  
  1.6       +14 -4     jakarta-commons/digester/src/test/org/apache/commons/digester/RulesBaseTestCase.java
  
  Index: RulesBaseTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RulesBaseTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RulesBaseTestCase.java	23 Mar 2002 17:45:59 -0000	1.5
  +++ RulesBaseTestCase.java	10 Jul 2002 18:12:33 -0000	1.6
  @@ -228,6 +228,16 @@
                   "*/c/d",
                   ((TestRule) digester.getRules().match(null, "x/c/d").iterator().next()).getIdentifier());
   
  +        // Test wildcard tail matching at the top level,
  +        // i.e. the wildcard is nothing
  +        digester.addRule("*/a", new TestRule("*/a"));
  +        assertEquals("Wildcard tail matching rule 3",
  +                     1,
  +                     digester.getRules().match(null,"a").size());
  +
  +        assertEquals("Wildcard tail matching rule 3 (match too much)",
  +                     0,
  +                     digester.getRules().match(null,"aa").size());
           // clean up
           digester.getRules().clear();
   
  
  
  
  1.5       +5 -5      jakarta-commons/digester/src/test/org/apache/commons/digester/TestRuleSet.java
  
  Index: TestRuleSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/TestRuleSet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestRuleSet.java	23 Jan 2002 22:38:01 -0000	1.4
  +++ TestRuleSet.java	10 Jul 2002 18:12:33 -0000	1.5
  @@ -152,6 +152,6 @@
                   "addAddress");
   
       }
  -
  +    
   
   }
  
  
  

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


Mime
View raw message