8074678: JCK test java_util/regex/MatchResult/index.html starts failing after JDK-8071479
To add non-match sanity check Reviewed-by: psandoz
This commit is contained in:
parent
cdeddbfbca
commit
f3a2e4480d
@ -292,11 +292,13 @@ public final class Matcher implements MatchResult {
|
||||
|
||||
@Override
|
||||
public int start() {
|
||||
checkMatch();
|
||||
return first;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int start(int group) {
|
||||
checkMatch();
|
||||
if (group < 0 || group > groupCount)
|
||||
throw new IndexOutOfBoundsException("No group " + group);
|
||||
return groups[group * 2];
|
||||
@ -304,11 +306,13 @@ public final class Matcher implements MatchResult {
|
||||
|
||||
@Override
|
||||
public int end() {
|
||||
checkMatch();
|
||||
return last;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int end(int group) {
|
||||
checkMatch();
|
||||
if (group < 0 || group > groupCount)
|
||||
throw new IndexOutOfBoundsException("No group " + group);
|
||||
return groups[group * 2 + 1];
|
||||
@ -321,17 +325,25 @@ public final class Matcher implements MatchResult {
|
||||
|
||||
@Override
|
||||
public String group() {
|
||||
checkMatch();
|
||||
return group(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String group(int group) {
|
||||
checkMatch();
|
||||
if (group < 0 || group > groupCount)
|
||||
throw new IndexOutOfBoundsException("No group " + group);
|
||||
if ((groups[group*2] == -1) || (groups[group*2+1] == -1))
|
||||
return null;
|
||||
return text.subSequence(groups[group * 2], groups[group * 2 + 1]).toString();
|
||||
}
|
||||
|
||||
private void checkMatch() {
|
||||
if (first < 0)
|
||||
throw new IllegalStateException("No match found");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@
|
||||
* 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
|
||||
* 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
|
||||
* 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
|
||||
* 8027645 8035076 8039124 8035975
|
||||
* 8027645 8035076 8039124 8035975 8074678
|
||||
*/
|
||||
|
||||
import java.util.function.Function;
|
||||
@ -138,6 +138,7 @@ public class RegExTest {
|
||||
wordSearchTest();
|
||||
hitEndTest();
|
||||
toMatchResultTest();
|
||||
toMatchResultTest2();
|
||||
surrogatesInClassTest();
|
||||
removeQEQuotingTest();
|
||||
namedGroupCaptureTest();
|
||||
@ -371,6 +372,47 @@ public class RegExTest {
|
||||
report("toMatchResult is a copy");
|
||||
}
|
||||
|
||||
private static void checkExpectedISE(Runnable test) {
|
||||
try {
|
||||
test.run();
|
||||
failCount++;
|
||||
} catch (IllegalStateException x) {
|
||||
} catch (IndexOutOfBoundsException xx) {
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkExpectedIOOE(Runnable test) {
|
||||
try {
|
||||
test.run();
|
||||
failCount++;
|
||||
} catch (IndexOutOfBoundsException x) {}
|
||||
}
|
||||
|
||||
// This is for bug 8074678
|
||||
// Test the result of toMatchResult throws ISE if no match is availble
|
||||
private static void toMatchResultTest2() throws Exception {
|
||||
Matcher matcher = Pattern.compile("nomatch").matcher("hello world");
|
||||
matcher.find();
|
||||
MatchResult mr = matcher.toMatchResult();
|
||||
|
||||
checkExpectedISE(() -> mr.start());
|
||||
checkExpectedISE(() -> mr.start(2));
|
||||
checkExpectedISE(() -> mr.end());
|
||||
checkExpectedISE(() -> mr.end(2));
|
||||
checkExpectedISE(() -> mr.group());
|
||||
checkExpectedISE(() -> mr.group(2));
|
||||
|
||||
matcher = Pattern.compile("(match)").matcher("there is a match");
|
||||
matcher.find();
|
||||
MatchResult mr2 = matcher.toMatchResult();
|
||||
checkExpectedIOOE(() -> mr2.start(2));
|
||||
checkExpectedIOOE(() -> mr2.end(2));
|
||||
checkExpectedIOOE(() -> mr2.group(2));
|
||||
|
||||
report("toMatchResult2 appropriate exceptions");
|
||||
}
|
||||
|
||||
// This is for bug 5013885
|
||||
// Must test a slice to see if it reports hitEnd correctly
|
||||
private static void hitEndTest() throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user