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 8221431 8224789 8228352 8230829 8236034
39 *
40 * @library /test/lib
41 * @library /lib/testlibrary/java/lang
42 * @build jdk.test.lib.RandomFactory
43 * @run main RegExTest
44 * @key randomness
45 */
46
47 import java.io.BufferedReader;
48 import java.io.ByteArrayInputStream;
49 import java.io.ByteArrayOutputStream;
50 import java.io.File;
51 import java.io.FileInputStream;
52 import java.io.InputStreamReader;
53 import java.io.ObjectInputStream;
54 import java.io.ObjectOutputStream;
55 import java.math.BigInteger;
56 import java.nio.CharBuffer;
57 import java.nio.file.Files;
58 import java.util.ArrayList;
169 namedGroupCaptureTest();
170 nonBmpClassComplementTest();
171 unicodePropertiesTest();
172 unicodeHexNotationTest();
173 unicodeClassesTest();
174 unicodeCharacterNameTest();
175 horizontalAndVerticalWSTest();
176 linebreakTest();
177 branchTest();
178 groupCurlyNotFoundSuppTest();
179 groupCurlyBackoffTest();
180 patternAsPredicate();
181 patternAsMatchPredicate();
182 invalidFlags();
183 embeddedFlags();
184 grapheme();
185 expoBacktracking();
186 invalidGroupName();
187 illegalRepetitionRange();
188 surrogatePairWithCanonEq();
189
190 if (failure) {
191 throw new
192 RuntimeException("RegExTest failed, 1st failure: " +
193 firstFailure);
194 } else {
195 System.err.println("OKAY: All tests passed.");
196 }
197 }
198
199 // Utility functions
200
201 private static String getRandomAlphaString(int length) {
202 StringBuffer buf = new StringBuffer(length);
203 for (int i=0; i<length; i++) {
204 char randChar = (char)(97 + generator.nextInt(26));
205 buf.append(randChar);
206 }
207 return buf.toString();
208 }
4982 if (!e.getMessage().startsWith("Illegal repetition")) {
4983 failCount++;
4984 System.out.println("Unexpected error message: " + e.getMessage());
4985 }
4986 } catch (Throwable t) {
4987 failCount++;
4988 System.out.println("Unexpected exception: " + t);
4989 }
4990 }
4991 report("illegalRepetitionRange");
4992 }
4993
4994 private static void surrogatePairWithCanonEq() {
4995 try {
4996 Pattern.compile("\ud834\udd21", Pattern.CANON_EQ);
4997 } catch (Throwable t) {
4998 failCount++;
4999 System.out.println("Unexpected exception: " + t);
5000 }
5001 report("surrogatePairWithCanonEq");
5002 }
5003 }
|
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 8221431 8224789 8228352 8230829 8236034 8214245
39 *
40 * @library /test/lib
41 * @library /lib/testlibrary/java/lang
42 * @build jdk.test.lib.RandomFactory
43 * @run main RegExTest
44 * @key randomness
45 */
46
47 import java.io.BufferedReader;
48 import java.io.ByteArrayInputStream;
49 import java.io.ByteArrayOutputStream;
50 import java.io.File;
51 import java.io.FileInputStream;
52 import java.io.InputStreamReader;
53 import java.io.ObjectInputStream;
54 import java.io.ObjectOutputStream;
55 import java.math.BigInteger;
56 import java.nio.CharBuffer;
57 import java.nio.file.Files;
58 import java.util.ArrayList;
169 namedGroupCaptureTest();
170 nonBmpClassComplementTest();
171 unicodePropertiesTest();
172 unicodeHexNotationTest();
173 unicodeClassesTest();
174 unicodeCharacterNameTest();
175 horizontalAndVerticalWSTest();
176 linebreakTest();
177 branchTest();
178 groupCurlyNotFoundSuppTest();
179 groupCurlyBackoffTest();
180 patternAsPredicate();
181 patternAsMatchPredicate();
182 invalidFlags();
183 embeddedFlags();
184 grapheme();
185 expoBacktracking();
186 invalidGroupName();
187 illegalRepetitionRange();
188 surrogatePairWithCanonEq();
189 caseInsensitivePMatch();
190
191 if (failure) {
192 throw new
193 RuntimeException("RegExTest failed, 1st failure: " +
194 firstFailure);
195 } else {
196 System.err.println("OKAY: All tests passed.");
197 }
198 }
199
200 // Utility functions
201
202 private static String getRandomAlphaString(int length) {
203 StringBuffer buf = new StringBuffer(length);
204 for (int i=0; i<length; i++) {
205 char randChar = (char)(97 + generator.nextInt(26));
206 buf.append(randChar);
207 }
208 return buf.toString();
209 }
4983 if (!e.getMessage().startsWith("Illegal repetition")) {
4984 failCount++;
4985 System.out.println("Unexpected error message: " + e.getMessage());
4986 }
4987 } catch (Throwable t) {
4988 failCount++;
4989 System.out.println("Unexpected exception: " + t);
4990 }
4991 }
4992 report("illegalRepetitionRange");
4993 }
4994
4995 private static void surrogatePairWithCanonEq() {
4996 try {
4997 Pattern.compile("\ud834\udd21", Pattern.CANON_EQ);
4998 } catch (Throwable t) {
4999 failCount++;
5000 System.out.println("Unexpected exception: " + t);
5001 }
5002 report("surrogatePairWithCanonEq");
5003 }
5004
5005 // This test is for 8214245
5006 private static void caseInsensitivePMatch() {
5007 for (String input : List.of("abcd", "AbCd", "ABCD")) {
5008 for (String pattern : List.of("abcd", "aBcD", "[a-d]{4}",
5009 "(?:a|b|c|d){4}", "\\p{Lower}{4}", "\\p{Ll}{4}",
5010 "\\p{IsLl}{4}", "\\p{gc=Ll}{4}",
5011 "\\p{general_category=Ll}{4}", "\\p{IsLowercase}{4}",
5012 "\\p{javaLowerCase}{4}", "\\p{Upper}{4}", "\\p{Lu}{4}",
5013 "\\p{IsLu}{4}", "\\p{gc=Lu}{4}", "\\p{general_category=Lu}{4}",
5014 "\\p{IsUppercase}{4}", "\\p{javaUpperCase}{4}",
5015 "\\p{Lt}{4}", "\\p{IsLt}{4}", "\\p{gc=Lt}{4}",
5016 "\\p{general_category=Lt}{4}", "\\p{IsTitlecase}{4}",
5017 "\\p{javaTitleCase}{4}", "[\\p{Lower}]{4}", "[\\p{Ll}]{4}",
5018 "[\\p{IsLl}]{4}", "[\\p{gc=Ll}]{4}",
5019 "[\\p{general_category=Ll}]{4}", "[\\p{IsLowercase}]{4}",
5020 "[\\p{javaLowerCase}]{4}", "[\\p{Upper}]{4}", "[\\p{Lu}]{4}",
5021 "[\\p{IsLu}]{4}", "[\\p{gc=Lu}]{4}",
5022 "[\\p{general_category=Lu}]{4}", "[\\p{IsUppercase}]{4}",
5023 "[\\p{javaUpperCase}]{4}", "[\\p{Lt}]{4}", "[\\p{IsLt}]{4}",
5024 "[\\p{gc=Lt}]{4}", "[\\p{general_category=Lt}]{4}",
5025 "[\\p{IsTitlecase}]{4}", "[\\p{javaTitleCase}]{4}"))
5026 {
5027 if (!Pattern.compile(pattern, Pattern.CASE_INSENSITIVE)
5028 .matcher(input)
5029 .matches())
5030 {
5031 failCount++;
5032 System.out.println("Expected to match: " +
5033 "'" + input + "' =~ /" + pattern + "/");
5034 }
5035 }
5036 }
5037
5038 for (String input : List.of("\u01c7", "\u01c8", "\u01c9")) {
5039 for (String pattern : List.of("\u01c7", "\u01c8", "\u01c9",
5040 "[\u01c7\u01c8]", "[\u01c7\u01c9]", "[\u01c8\u01c9]",
5041 "[\u01c7-\u01c8]", "[\u01c8-\u01c9]", "[\u01c7-\u01c9]",
5042 "\\p{Lower}", "\\p{Ll}", "\\p{IsLl}", "\\p{gc=Ll}",
5043 "\\p{general_category=Ll}", "\\p{IsLowercase}",
5044 "\\p{javaLowerCase}", "\\p{Upper}", "\\p{Lu}",
5045 "\\p{IsLu}", "\\p{gc=Lu}", "\\p{general_category=Lu}",
5046 "\\p{IsUppercase}", "\\p{javaUpperCase}",
5047 "\\p{Lt}", "\\p{IsLt}", "\\p{gc=Lt}",
5048 "\\p{general_category=Lt}", "\\p{IsTitlecase}",
5049 "\\p{javaTitleCase}", "[\\p{Lower}]", "[\\p{Ll}]",
5050 "[\\p{IsLl}]", "[\\p{gc=Ll}]",
5051 "[\\p{general_category=Ll}]", "[\\p{IsLowercase}]",
5052 "[\\p{javaLowerCase}]", "[\\p{Upper}]", "[\\p{Lu}]",
5053 "[\\p{IsLu}]", "[\\p{gc=Lu}]",
5054 "[\\p{general_category=Lu}]", "[\\p{IsUppercase}]",
5055 "[\\p{javaUpperCase}]", "[\\p{Lt}]", "[\\p{IsLt}]",
5056 "[\\p{gc=Lt}]", "[\\p{general_category=Lt}]",
5057 "[\\p{IsTitlecase}]", "[\\p{javaTitleCase}]"))
5058 {
5059 if (!Pattern.compile(pattern, Pattern.CASE_INSENSITIVE
5060 | Pattern.UNICODE_CHARACTER_CLASS)
5061 .matcher(input)
5062 .matches())
5063 {
5064 failCount++;
5065 System.out.println("Expected to match: " +
5066 "'" + input + "' =~ /" + pattern + "/");
5067 }
5068 }
5069 }
5070 report("caseInsensitivePMatch");
5071 }
5072 }
|