< prev index next >

test/jdk/java/util/regex/RegExTest.java

Print this page




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @summary tests RegExp framework (use -Dseed=X to set PRNG seed)
  27  * @author Mike McCloskey
  28  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
  29  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
  30  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
  31  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  32  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  33  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  34  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
  35  * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
  36  * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
  37  * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
  38  * 8194667 8197462
  39  *
  40  * @library /test/lib
  41  * @build jdk.test.lib.RandomFactory
  42  * @run main RegExTest
  43  * @key randomness
  44  */
  45 
  46 import java.util.function.Function;
  47 import java.util.regex.*;
  48 import java.util.Random;
  49 import java.util.Scanner;
  50 import java.io.*;
  51 import java.nio.file.*;
  52 import java.util.*;
  53 import java.nio.CharBuffer;
  54 import java.util.function.Predicate;
  55 import jdk.test.lib.RandomFactory;
  56 
  57 /**
  58  * This is a test class created to check the operation of


 147         unicodeWordBoundsTest();
 148         caretAtEndTest();
 149         wordSearchTest();
 150         hitEndTest();
 151         toMatchResultTest();
 152         toMatchResultTest2();
 153         surrogatesInClassTest();
 154         removeQEQuotingTest();
 155         namedGroupCaptureTest();
 156         nonBmpClassComplementTest();
 157         unicodePropertiesTest();
 158         unicodeHexNotationTest();
 159         unicodeClassesTest();
 160         unicodeCharacterNameTest();
 161         horizontalAndVerticalWSTest();
 162         linebreakTest();
 163         branchTest();
 164         groupCurlyNotFoundSuppTest();
 165         groupCurlyBackoffTest();
 166         patternAsPredicate();

 167         invalidFlags();
 168         embeddedFlags();
 169         grapheme();
 170         expoBacktracking();
 171         invalidGroupName();
 172 
 173         if (failure) {
 174             throw new
 175                 RuntimeException("RegExTest failed, 1st failure: " +
 176                                  firstFailure);
 177         } else {
 178             System.err.println("OKAY: All tests passed.");
 179         }
 180     }
 181 
 182     // Utility functions
 183 
 184     private static String getRandomAlphaString(int length) {
 185         StringBuffer buf = new StringBuffer(length);
 186         for (int i=0; i<length; i++) {


4669         }
4670         report("GroupCurly backoff");
4671     }
4672 
4673     // This test is for 8012646
4674     private static void patternAsPredicate() throws Exception {
4675         Predicate<String> p = Pattern.compile("[a-z]+").asPredicate();
4676 
4677         if (p.test("")) {
4678             failCount++;
4679         }
4680         if (!p.test("word")) {
4681             failCount++;
4682         }
4683         if (p.test("1234")) {
4684             failCount++;
4685         }
4686         report("Pattern.asPredicate");
4687     }
4688 




















4689     // This test is for 8035975
4690     private static void invalidFlags() throws Exception {
4691         for (int flag = 1; flag != 0; flag <<= 1) {
4692             switch (flag) {
4693             case Pattern.CASE_INSENSITIVE:
4694             case Pattern.MULTILINE:
4695             case Pattern.DOTALL:
4696             case Pattern.UNICODE_CASE:
4697             case Pattern.CANON_EQ:
4698             case Pattern.UNIX_LINES:
4699             case Pattern.LITERAL:
4700             case Pattern.UNICODE_CHARACTER_CLASS:
4701             case Pattern.COMMENTS:
4702                 // valid flag, continue
4703                 break;
4704             default:
4705                 try {
4706                     Pattern.compile(".", flag);
4707                     failCount++;
4708                 } catch (IllegalArgumentException expected) {




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @summary tests RegExp framework (use -Dseed=X to set PRNG seed)
  27  * @author Mike McCloskey
  28  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
  29  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
  30  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
  31  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  32  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  33  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  34  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
  35  * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
  36  * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
  37  * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
  38  * 8194667 8197462 8184692
  39  *
  40  * @library /test/lib
  41  * @build jdk.test.lib.RandomFactory
  42  * @run main RegExTest
  43  * @key randomness
  44  */
  45 
  46 import java.util.function.Function;
  47 import java.util.regex.*;
  48 import java.util.Random;
  49 import java.util.Scanner;
  50 import java.io.*;
  51 import java.nio.file.*;
  52 import java.util.*;
  53 import java.nio.CharBuffer;
  54 import java.util.function.Predicate;
  55 import jdk.test.lib.RandomFactory;
  56 
  57 /**
  58  * This is a test class created to check the operation of


 147         unicodeWordBoundsTest();
 148         caretAtEndTest();
 149         wordSearchTest();
 150         hitEndTest();
 151         toMatchResultTest();
 152         toMatchResultTest2();
 153         surrogatesInClassTest();
 154         removeQEQuotingTest();
 155         namedGroupCaptureTest();
 156         nonBmpClassComplementTest();
 157         unicodePropertiesTest();
 158         unicodeHexNotationTest();
 159         unicodeClassesTest();
 160         unicodeCharacterNameTest();
 161         horizontalAndVerticalWSTest();
 162         linebreakTest();
 163         branchTest();
 164         groupCurlyNotFoundSuppTest();
 165         groupCurlyBackoffTest();
 166         patternAsPredicate();
 167         patternAsMatchPredicate();
 168         invalidFlags();
 169         embeddedFlags();
 170         grapheme();
 171         expoBacktracking();
 172         invalidGroupName();
 173 
 174         if (failure) {
 175             throw new
 176                 RuntimeException("RegExTest failed, 1st failure: " +
 177                                  firstFailure);
 178         } else {
 179             System.err.println("OKAY: All tests passed.");
 180         }
 181     }
 182 
 183     // Utility functions
 184 
 185     private static String getRandomAlphaString(int length) {
 186         StringBuffer buf = new StringBuffer(length);
 187         for (int i=0; i<length; i++) {


4670         }
4671         report("GroupCurly backoff");
4672     }
4673 
4674     // This test is for 8012646
4675     private static void patternAsPredicate() throws Exception {
4676         Predicate<String> p = Pattern.compile("[a-z]+").asPredicate();
4677 
4678         if (p.test("")) {
4679             failCount++;
4680         }
4681         if (!p.test("word")) {
4682             failCount++;
4683         }
4684         if (p.test("1234")) {
4685             failCount++;
4686         }
4687         report("Pattern.asPredicate");
4688     }
4689 
4690     // This test is for 8184692
4691     private static void patternAsMatchPredicate() throws Exception {
4692         Predicate<String> p = Pattern.compile("[a-z]+").asMatchPredicate();
4693 
4694         if (p.test("")) {
4695             failCount++;
4696         }
4697         if (!p.test("word")) {
4698             failCount++;
4699         }
4700         if (p.test("1234word")) {
4701             failCount++;
4702         }
4703         if (p.test("1234")) {
4704             failCount++;
4705         }
4706         report("Pattern.asMatchPredicate");
4707     }
4708 
4709 
4710     // This test is for 8035975
4711     private static void invalidFlags() throws Exception {
4712         for (int flag = 1; flag != 0; flag <<= 1) {
4713             switch (flag) {
4714             case Pattern.CASE_INSENSITIVE:
4715             case Pattern.MULTILINE:
4716             case Pattern.DOTALL:
4717             case Pattern.UNICODE_CASE:
4718             case Pattern.CANON_EQ:
4719             case Pattern.UNIX_LINES:
4720             case Pattern.LITERAL:
4721             case Pattern.UNICODE_CHARACTER_CLASS:
4722             case Pattern.COMMENTS:
4723                 // valid flag, continue
4724                 break;
4725             default:
4726                 try {
4727                     Pattern.compile(".", flag);
4728                     failCount++;
4729                 } catch (IllegalArgumentException expected) {


< prev index next >