harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r590138 - /harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/MatcherTest.java
Date Tue, 30 Oct 2007 16:37:25 GMT
Author: tellison
Date: Tue Oct 30 09:37:17 2007
New Revision: 590138

URL: http://svn.apache.org/viewvc?rev=590138&view=rev
Log:
Apply regression test for HARMONY-4396 ([classlib][regex] Matcher.hitEnd() returns invalid
value if a match isn't found after find() method is called)

Modified:
    harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/MatcherTest.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=590138&r1=590137&r2=590138&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
Tue Oct 30 09:37:17 2007
@@ -714,6 +714,53 @@
         }
     }
 
+    /**
+     * Regression test for HARMONY-4396
+     */
+    public void testHitEndAfterFind() {
+        hitEndTest(true, "#01.0", "r((ege)|(geg))x", "regexx", false);
+        hitEndTest(true, "#01.1", "r((ege)|(geg))x", "regex", false);
+        hitEndTest(true, "#01.2", "r((ege)|(geg))x", "rege", true);
+        hitEndTest(true, "#01.2", "r((ege)|(geg))x", "xregexx", false);
+
+        hitEndTest(true, "#02.0", "regex", "rexreger", true);
+        hitEndTest(true, "#02.1", "regex", "raxregexr", false);
+
+        String floatRegex = getHexFloatRegex();
+        hitEndTest(true, "#03.0", floatRegex, Double.toHexString(-1.234d), true);
+        hitEndTest(true, "#03.1", floatRegex, "1 ABC"
+                + Double.toHexString(Double.NaN) + "buhuhu", false);
+        hitEndTest(true, "#03.2", floatRegex, Double.toHexString(-0.0) + "--",
+                false);
+        hitEndTest(true, "#03.3", floatRegex, "--"
+                + Double.toHexString(Double.MIN_VALUE) + "--", false);
+
+        hitEndTest(true, "#04.0", "(\\d+) fish (\\d+) fish (\\w+) fish (\\d+)",
+                "1 fish 2 fish red fish 5", true);
+        hitEndTest(true, "#04.1", "(\\d+) fish (\\d+) fish (\\w+) fish (\\d+)",
+                "----1 fish 2 fish red fish 5----", false);
+    }
+
+    private void hitEndTest(boolean callFind, String testNo, String regex,
+            String input, boolean hit) {
+        Pattern pattern = Pattern.compile(regex);
+        Matcher matcher = pattern.matcher(input);
+        if (callFind) {
+            matcher.find();
+        } else {
+            matcher.matches();
+        }
+        boolean h = matcher.hitEnd();
+
+        assertTrue(testNo, h == hit);
+    }
+
+    private String getHexFloatRegex() {
+        String hexDecimal = "(-|\\+)?0[xX][0-9a-fA-F]*\\.[0-9a-fA-F]+([pP](-|\\+)?[0-9]+)?";
+        String notANumber = "((-|\\+)?Infinity)|([nN]a[nN])";
+        return new StringBuilder("((").append(hexDecimal).append(")|(").append(
+                notANumber).append("))").toString();
+    }
 
     public static void main(String[] args) {
 		junit.textui.TestRunner.run(MatcherTest.class);



Mime
View raw message