jdk/test/java/util/regex/RegExTest.java
changeset 11287 3db172a5433c
parent 9536 648c9add2a74
child 12432 748fcaa0e0c1
equal deleted inserted replaced
11286:a49be3718db9 11287:3db172a5433c
    30  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
    30  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
    31  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
    31  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
    32  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
    32  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
    33  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
    33  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
    34  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
    34  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
    35  * 6350801 6676425 6878475 6919132 6931676 6948903 7014645 7039066
    35  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
    36  */
    36  */
    37 
    37 
    38 import java.util.regex.*;
    38 import java.util.regex.*;
    39 import java.util.Random;
    39 import java.util.Random;
    40 import java.io.*;
    40 import java.io.*;
    48 public class RegExTest {
    48 public class RegExTest {
    49 
    49 
    50     private static Random generator = new Random();
    50     private static Random generator = new Random();
    51     private static boolean failure = false;
    51     private static boolean failure = false;
    52     private static int failCount = 0;
    52     private static int failCount = 0;
       
    53     private static String firstFailure = null;
    53 
    54 
    54     /**
    55     /**
    55      * Main to interpret arguments and run several tests.
    56      * Main to interpret arguments and run several tests.
    56      *
    57      *
    57      */
    58      */
   131         caretAtEndTest();
   132         caretAtEndTest();
   132         wordSearchTest();
   133         wordSearchTest();
   133         hitEndTest();
   134         hitEndTest();
   134         toMatchResultTest();
   135         toMatchResultTest();
   135         surrogatesInClassTest();
   136         surrogatesInClassTest();
       
   137         removeQEQuotingTest();
   136         namedGroupCaptureTest();
   138         namedGroupCaptureTest();
   137         nonBmpClassComplementTest();
   139         nonBmpClassComplementTest();
   138         unicodePropertiesTest();
   140         unicodePropertiesTest();
   139         unicodeHexNotationTest();
   141         unicodeHexNotationTest();
   140         unicodeClassesTest();
   142         unicodeClassesTest();
   141         if (failure)
   143         if (failure) {
   142             throw new RuntimeException("Failure in the RE handling.");
   144             throw new
   143         else
   145                 RuntimeException("RegExTest failed, 1st failure: " +
       
   146                                  firstFailure);
       
   147         } else {
   144             System.err.println("OKAY: All tests passed.");
   148             System.err.println("OKAY: All tests passed.");
       
   149         }
   145     }
   150     }
   146 
   151 
   147     // Utility functions
   152     // Utility functions
   148 
   153 
   149     private static String getRandomAlphaString(int length) {
   154     private static String getRandomAlphaString(int length) {
   213         for (int i=0; i<spacesToAdd; i++)
   218         for (int i=0; i<spacesToAdd; i++)
   214             paddedNameBuffer.append(" ");
   219             paddedNameBuffer.append(" ");
   215         String paddedName = paddedNameBuffer.toString();
   220         String paddedName = paddedNameBuffer.toString();
   216         System.err.println(paddedName + ": " +
   221         System.err.println(paddedName + ": " +
   217                            (failCount==0 ? "Passed":"Failed("+failCount+")"));
   222                            (failCount==0 ? "Passed":"Failed("+failCount+")"));
   218         if (failCount > 0)
   223         if (failCount > 0) {
   219             failure = true;
   224             failure = true;
       
   225 
       
   226             if (firstFailure == null) {
       
   227                 firstFailure = testName;
       
   228             }
       
   229         }
       
   230 
   220         failCount = 0;
   231         failCount = 0;
   221     }
   232     }
   222 
   233 
   223     /**
   234     /**
   224      * Converts ASCII alphabet characters [A-Za-z] in the given 's' to
   235      * Converts ASCII alphabet characters [A-Za-z] in the given 's' to
   293     private static void surrogatesInClassTest() throws Exception {
   304     private static void surrogatesInClassTest() throws Exception {
   294         Pattern pattern = Pattern.compile("[\\ud834\\udd21-\\ud834\\udd24]");
   305         Pattern pattern = Pattern.compile("[\\ud834\\udd21-\\ud834\\udd24]");
   295         Matcher matcher = pattern.matcher("\ud834\udd22");
   306         Matcher matcher = pattern.matcher("\ud834\udd22");
   296         if (!matcher.find())
   307         if (!matcher.find())
   297             failCount++;
   308             failCount++;
       
   309 
       
   310         report("Surrogate pair in Unicode escape");
       
   311     }
       
   312 
       
   313     // This is for bug6990617
       
   314     // Test if Pattern.RemoveQEQuoting works correctly if the octal unicode
       
   315     // char encoding is only 2 or 3 digits instead of 4 and the first quoted
       
   316     // char is an octal digit.
       
   317     private static void removeQEQuotingTest() throws Exception {
       
   318         Pattern pattern =
       
   319             Pattern.compile("\\011\\Q1sometext\\E\\011\\Q2sometext\\E");
       
   320         Matcher matcher = pattern.matcher("\t1sometext\t2sometext");
       
   321         if (!matcher.find())
       
   322             failCount++;
       
   323 
       
   324         report("Remove Q/E Quoting");
   298     }
   325     }
   299 
   326 
   300     // This is for bug 4988891
   327     // This is for bug 4988891
   301     // Test toMatchResult to see that it is a copy of the Matcher
   328     // Test toMatchResult to see that it is a copy of the Matcher
   302     // that is not affected by subsequent operations on the original
   329     // that is not affected by subsequent operations on the original