test/java/util/regex/RegExTest.java
Print this page
@@ -31,11 +31,11 @@
* 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
* 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
* 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
* 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
* 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
- * 7067045 7014640 7189363 8007395
+ * 7067045 7014640 7189363 8007395 8013252 8013254
*/
import java.util.regex.*;
import java.util.Random;
import java.io.*;
@@ -3388,11 +3388,13 @@
}
private static void check(Pattern p, String s, String g, String expected) {
Matcher m = p.matcher(s);
m.find();
- if (!m.group(g).equals(expected))
+ if (!m.group(g).equals(expected) ||
+ s.charAt(m.start(g)) != expected.charAt(0) ||
+ s.charAt(m.end(g) - 1) != expected.charAt(expected.length() - 1))
failCount++;
}
private static void checkReplaceFirst(String p, String s, String r, String expected)
{
@@ -3418,23 +3420,46 @@
return;
}
failCount++;
}
- private static void checkExpectedFail(Matcher m, String g) {
+ private static void checkExpectedIAE(Matcher m, String g) {
m.find();
try {
m.group(g);
- } catch (IllegalArgumentException iae) {
+ } catch (IllegalArgumentException x) {
//iae.printStackTrace();
- return;
- } catch (NullPointerException npe) {
+ try {
+ m.start(g);
+ } catch (IllegalArgumentException xx) {
+ try {
+ m.start(g);
+ } catch (IllegalArgumentException xxx) {
return;
}
+ }
+ }
failCount++;
}
+ private static void checkExpectedNPE(Matcher m) {
+ m.find();
+ try {
+ m.group(null);
+ } catch (NullPointerException x) {
+ try {
+ m.start(null);
+ } catch (NullPointerException xx) {
+ try {
+ m.end(null);
+ } catch (NullPointerException xxx) {
+ return;
+ }
+ }
+ }
+ failCount++;
+ }
private static void namedGroupCaptureTest() throws Exception {
check(Pattern.compile("x+(?<gname>y+)z+"),
"xxxyyyzzz",
"gname",
@@ -3557,14 +3582,13 @@
checkExpectedFail("(?<groupnamehasnoascii.in>abc)(def)");
checkExpectedFail("(?<groupnamehasnoascii_in>abc)(def)");
checkExpectedFail("(?<6groupnamestartswithdigit>abc)(def)");
checkExpectedFail("(?<gname>abc)(def)\\k<gnameX>");
checkExpectedFail("(?<gname>abc)(?<gname>def)\\k<gnameX>");
- checkExpectedFail(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"),
+ checkExpectedIAE(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"),
"gnameX");
- checkExpectedFail(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"),
- null);
+ checkExpectedNPE(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"));
report("NamedGroupCapture");
}
// This is for bug 6969132
private static void nonBmpClassComplementTest() throws Exception {
@@ -3757,10 +3781,11 @@
Matcher ideogP = Pattern.compile("\\p{IsIdeographic}").matcher("");
Matcher cntrlP = Pattern.compile("\\p{IsControl}").matcher("");
Matcher spaceP = Pattern.compile("\\p{IsWhiteSpace}").matcher("");
Matcher definedP = Pattern.compile("\\p{IsAssigned}").matcher("");
Matcher nonCCPP = Pattern.compile("\\p{IsNoncharacterCodePoint}").matcher("");
+ Matcher joinCrtl = Pattern.compile("\\p{IsJoinControl}").matcher("");
// javaMethod
Matcher lowerJ = Pattern.compile("\\p{javaLowerCase}").matcher("");
Matcher upperJ = Pattern.compile("\\p{javaUpperCase}").matcher("");
Matcher alphaJ = Pattern.compile("\\p{javaAlphabetic}").matcher("");
@@ -3827,11 +3852,12 @@
Character.isTitleCase(cp) != titleP.reset(str).matches() ||
Character.isLetter(cp) != letterP.reset(str).matches()||
Character.isIdeographic(cp) != ideogP.reset(str).matches() ||
Character.isIdeographic(cp) != ideogJ.reset(str).matches() ||
(Character.UNASSIGNED == type) == definedP.reset(str).matches() ||
- POSIX_Unicode.isNoncharacterCodePoint(cp) != nonCCPP.reset(str).matches())
+ POSIX_Unicode.isNoncharacterCodePoint(cp) != nonCCPP.reset(str).matches() ||
+ POSIX_Unicode.isJoinControl(cp) != joinCrtl.reset(str).matches())
failCount++;
}
// bounds/word align
twoFindIndexes(" \u0180sherman\u0400 ", bound, 1, 10);