16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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 * @library /lib/testlibrary
37 * @build jdk.testlibrary.*
38 * @run main RegExTest
39 * @key randomness
40 */
41
42 import java.util.function.Function;
43 import java.util.regex.*;
44 import java.util.Random;
45 import java.util.Scanner;
46 import java.io.*;
47 import java.nio.file.*;
48 import java.util.*;
49 import java.nio.CharBuffer;
50 import java.util.function.Predicate;
51 import jdk.testlibrary.RandomFactory;
52
53 /**
54 * This is a test class created to check the operation of
55 * the Pattern and Matcher classes.
4075 "${dog}",
4076 "zzzDogzzzDogzzz");
4077
4078 // backref in Matcher & String
4079 if (!"abcdefghij".replaceFirst("cd(?<gn>ef)gh", "${gn}").equals("abefij") ||
4080 !"abbbcbdbefgh".replaceAll("(?<gn>[a-e])b", "${gn}").equals("abcdefgh"))
4081 failCount++;
4082
4083 // negative
4084 checkExpectedFail("(?<groupnamehasnoascii.in>abc)(def)");
4085 checkExpectedFail("(?<groupnamehasnoascii_in>abc)(def)");
4086 checkExpectedFail("(?<6groupnamestartswithdigit>abc)(def)");
4087 checkExpectedFail("(?<gname>abc)(def)\\k<gnameX>");
4088 checkExpectedFail("(?<gname>abc)(?<gname>def)\\k<gnameX>");
4089 checkExpectedIAE(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"),
4090 "gnameX");
4091 checkExpectedNPE(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"));
4092 report("NamedGroupCapture");
4093 }
4094
4095 // This is for bug 6969132
4096 private static void nonBmpClassComplementTest() throws Exception {
4097 Pattern p = Pattern.compile("\\P{Lu}");
4098 Matcher m = p.matcher(new String(new int[] {0x1d400}, 0, 1));
4099 if (m.find() && m.start() == 1)
4100 failCount++;
4101
4102 // from a unicode category
4103 p = Pattern.compile("\\P{Lu}");
4104 m = p.matcher(new String(new int[] {0x1d400}, 0, 1));
4105 if (m.find())
4106 failCount++;
4107 if (!m.hitEnd())
4108 failCount++;
4109
4110 // block
4111 p = Pattern.compile("\\P{InMathematicalAlphanumericSymbols}");
4112 m = p.matcher(new String(new int[] {0x1d400}, 0, 1));
4113 if (m.find() && m.start() == 1)
4114 failCount++;
4115
4116 report("NonBmpClassComplement");
4117 }
4118
4119 private static void unicodePropertiesTest() throws Exception {
4120 // different forms
4121 if (!Pattern.compile("\\p{IsLu}").matcher("A").matches() ||
4122 !Pattern.compile("\\p{Lu}").matcher("A").matches() ||
4123 !Pattern.compile("\\p{gc=Lu}").matcher("A").matches() ||
4124 !Pattern.compile("\\p{general_category=Lu}").matcher("A").matches() ||
4125 !Pattern.compile("\\p{IsLatin}").matcher("B").matches() ||
4126 !Pattern.compile("\\p{sc=Latin}").matcher("B").matches() ||
4127 !Pattern.compile("\\p{script=Latin}").matcher("B").matches() ||
4128 !Pattern.compile("\\p{InBasicLatin}").matcher("c").matches() ||
4129 !Pattern.compile("\\p{blk=BasicLatin}").matcher("c").matches() ||
4130 !Pattern.compile("\\p{block=BasicLatin}").matcher("c").matches())
4131 failCount++;
4132
4133 Matcher common = Pattern.compile("\\p{script=Common}").matcher("");
4134 Matcher unknown = Pattern.compile("\\p{IsUnknown}").matcher("");
4135 Matcher lastSM = common;
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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
37 * @library /lib/testlibrary
38 * @build jdk.testlibrary.*
39 * @run main RegExTest
40 * @key randomness
41 */
42
43 import java.util.function.Function;
44 import java.util.regex.*;
45 import java.util.Random;
46 import java.util.Scanner;
47 import java.io.*;
48 import java.nio.file.*;
49 import java.util.*;
50 import java.nio.CharBuffer;
51 import java.util.function.Predicate;
52 import jdk.testlibrary.RandomFactory;
53
54 /**
55 * This is a test class created to check the operation of
56 * the Pattern and Matcher classes.
4076 "${dog}",
4077 "zzzDogzzzDogzzz");
4078
4079 // backref in Matcher & String
4080 if (!"abcdefghij".replaceFirst("cd(?<gn>ef)gh", "${gn}").equals("abefij") ||
4081 !"abbbcbdbefgh".replaceAll("(?<gn>[a-e])b", "${gn}").equals("abcdefgh"))
4082 failCount++;
4083
4084 // negative
4085 checkExpectedFail("(?<groupnamehasnoascii.in>abc)(def)");
4086 checkExpectedFail("(?<groupnamehasnoascii_in>abc)(def)");
4087 checkExpectedFail("(?<6groupnamestartswithdigit>abc)(def)");
4088 checkExpectedFail("(?<gname>abc)(def)\\k<gnameX>");
4089 checkExpectedFail("(?<gname>abc)(?<gname>def)\\k<gnameX>");
4090 checkExpectedIAE(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"),
4091 "gnameX");
4092 checkExpectedNPE(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"));
4093 report("NamedGroupCapture");
4094 }
4095
4096 // This is for bug 6919132
4097 private static void nonBmpClassComplementTest() throws Exception {
4098 Pattern p = Pattern.compile("\\P{Lu}");
4099 Matcher m = p.matcher(new String(new int[] {0x1d400}, 0, 1));
4100
4101 if (m.find() && m.start() == 1)
4102 failCount++;
4103
4104 // from a unicode category
4105 p = Pattern.compile("\\P{Lu}");
4106 m = p.matcher(new String(new int[] {0x1d400}, 0, 1));
4107 if (m.find())
4108 failCount++;
4109 if (!m.hitEnd())
4110 failCount++;
4111
4112 // block
4113 p = Pattern.compile("\\P{InMathematicalAlphanumericSymbols}");
4114 m = p.matcher(new String(new int[] {0x1d400}, 0, 1));
4115 if (m.find() && m.start() == 1)
4116 failCount++;
4117
4118 p = Pattern.compile("\\P{sc=GRANTHA}");
4119 m = p.matcher(new String(new int[] {0x11350}, 0, 1));
4120 if (m.find() && m.start() == 1)
4121 failCount++;
4122
4123 report("NonBmpClassComplement");
4124 }
4125
4126 private static void unicodePropertiesTest() throws Exception {
4127 // different forms
4128 if (!Pattern.compile("\\p{IsLu}").matcher("A").matches() ||
4129 !Pattern.compile("\\p{Lu}").matcher("A").matches() ||
4130 !Pattern.compile("\\p{gc=Lu}").matcher("A").matches() ||
4131 !Pattern.compile("\\p{general_category=Lu}").matcher("A").matches() ||
4132 !Pattern.compile("\\p{IsLatin}").matcher("B").matches() ||
4133 !Pattern.compile("\\p{sc=Latin}").matcher("B").matches() ||
4134 !Pattern.compile("\\p{script=Latin}").matcher("B").matches() ||
4135 !Pattern.compile("\\p{InBasicLatin}").matcher("c").matches() ||
4136 !Pattern.compile("\\p{blk=BasicLatin}").matcher("c").matches() ||
4137 !Pattern.compile("\\p{block=BasicLatin}").matcher("c").matches())
4138 failCount++;
4139
4140 Matcher common = Pattern.compile("\\p{script=Common}").matcher("");
4141 Matcher unknown = Pattern.compile("\\p{IsUnknown}").matcher("");
4142 Matcher lastSM = common;
|