harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r766547 - in /harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex: MatcherTest.java PatternTest.java
Date Sun, 19 Apr 2009 23:53:31 GMT
Author: ndbeyer
Date: Sun Apr 19 23:53:30 2009
New Revision: 766547

URL: http://svn.apache.org/viewvc?rev=766547&view=rev
Log:
increase test coverage and clean up cruft

Modified:
    harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/MatcherTest.java
    harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternTest.java

Modified: harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/MatcherTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/MatcherTest.java?rev=766547&r1=766546&r2=766547&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/MatcherTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/MatcherTest.java
Sun Apr 19 23:53:30 2009
@@ -37,6 +37,45 @@
     String[] groupPatterns = { "(a|b)*aabb", "((a)|b)*aabb", "((a|b)*)a(abb)",
             "(((a)|(b))*)aabb", "(((a)|(b))*)aa(b)b", "(((a)|(b))*)a(a(b)b)" };
 
+    public MatcherTest(String name) {
+        super(name);
+    }
+    
+    public void testRegionsIntInt() {
+        Pattern p = Pattern.compile("x*");
+        Matcher m = p.matcher("axxxxxa");
+        assertFalse(m.matches());
+        
+        m.region(1, 6);
+        assertEquals(1, m.regionStart());
+        assertEquals(6, m.regionEnd());
+        assertTrue(m.matches());
+        
+        try {
+            m.region(1, 0);
+            fail("expected an IOOBE");
+        } catch(IndexOutOfBoundsException e) {
+        }
+        
+        try {
+            m.region(-1, 2);
+            fail("expected an IOOBE");
+        } catch(IndexOutOfBoundsException e) {
+        }
+        
+        try {
+            m.region(10, 11);
+            fail("expected an IOOBE");
+        } catch(IndexOutOfBoundsException e) {
+        }
+        
+        try {
+            m.region(1, 10);
+            fail("expected an IOOBE");
+        } catch(IndexOutOfBoundsException e) {
+        }
+    }
+    
     public void testAppendReplacement() {
         Pattern pat = Pattern.compile("XX");
         Matcher m = pat.matcher("Today is XX-XX-XX ...");
@@ -74,6 +113,17 @@
      * Class under test for Matcher reset(CharSequence)
      */
     public void testResetCharSequence() {
+        Pattern p = Pattern.compile("abcd");
+        Matcher m = p.matcher("abcd");
+        assertTrue(m.matches());
+        m.reset("efgh");
+        assertFalse(m.matches());
+        
+        try {
+            m.reset(null);
+            fail("expected a NPE");
+        } catch (NullPointerException e) {
+        }
     }
 
     public void testAppendSlashes() {
@@ -376,62 +426,6 @@
         assertEquals("b", mat.group());
     }
 
-    public void _testMatchesURI() {
-        final Pattern pat = Pattern
-                .compile("^(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
-        Runnable r1 = new Runnable() {
-            public void run() {
-                Matcher mat = pat
-                        .matcher("file:/c:/workspace/api/build.win32/classes/META-INF/"
-                                + "services/javax.xml.parsers.DocumentBuilderFactory");
-                while (mat.matches()) {
-                    // Do nothing
-                }
-                System.out.println("1: fail");
-            }
-        };
-
-        Runnable r2 = new Runnable() {
-            public void run() {
-                Matcher mat = pat.matcher("file:/c:/workspace/"
-                        + "services/javax.xml.parsers.DocumentBuilderFactory");
-                while (mat.matches()) {
-                    // Do nothing
-                }
-                System.out.println("2: fail");
-            }
-        };
-
-        Thread t1 = new Thread(r1);
-        Thread t2 = new Thread(r2);
-
-        t1.start();
-        t2.start();
-
-        try {
-            t1.join();
-            t2.join();
-        } catch (Exception e) {
-        }
-
-    }
-
-    public void _testUnifiedQuantifiers() {
-        // Pattern pat1 = Pattern.compile("\\s+a");
-        Pattern pat2 = Pattern.compile(" *a");
-
-        Matcher mat = pat2.matcher("      a");
-
-        System.out.println("unified: " + mat.find());
-    }
-
-    public void _testCompositeGroupQuantifiers() {
-        Pattern pat = Pattern.compile("(a|b){0,3}abb");
-        Matcher mat = pat.matcher("ababababababababababaab");
-
-        System.out.println("composite: " + mat.find());
-    }
-
     public void testPosCompositeGroup() {
         String[] posExamples = { "aabbcc", "aacc", "bbaabbcc" };
         String[] negExamples = { "aabb", "bb", "bbaabb" };
@@ -761,8 +755,4 @@
         return new StringBuilder("((").append(hexDecimal).append(")|(").append(
                 notANumber).append("))").toString();
     }
-
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(MatcherTest.class);
-    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternTest.java?rev=766547&r1=766546&r2=766547&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternTest.java
Sun Apr 19 23:53:30 2009
@@ -41,17 +41,14 @@
             "x(?c)y", "x(?cc)y", "x(?:c)y"
 
     };
-
-    /**
-     * Constructor for PatternTest.
-     * 
-     * @param name
-     */
+    
     public PatternTest(String name) {
         super(name);
     }
 
-    public void testMatcher() {
+    public void testCommentsInPattern() {
+        Pattern p = Pattern.compile("ab# this is a comment\ncd", Pattern.COMMENTS);
+        assertTrue(p.matcher("abcd").matches());
     }
 
     /*



Mime
View raw message