ICU-21747 Add check for expectedBreakCount in Java

This commit is contained in:
Jeff Genovy 2021-09-01 16:27:52 -07:00
parent 08dbf093ce
commit e2fe1aa8b7

View file

@ -553,6 +553,8 @@ public class RBBIMonkeyTest extends TestFmwk {
fRuleForPosition = new int[fString.length()+1];
f2ndRuleForPos = new int[fString.length()+1];
int expectedBreakCount = 0;
// Apply reference rules to find the expected breaks.
fExpectedBreaks[0] = true; // Force an expected break before the start of the text.
@ -619,6 +621,7 @@ public class RBBIMonkeyTest extends TestFmwk {
if (hasBreak) {
int breakPos = strIdx + BreakGroupStart(matchingRule.fRuleMatcher);
fExpectedBreaks[breakPos] = true;
expectedBreakCount++;
// System.out.printf("recording break at %d\n", breakPos);
// For the next iteration, pick up applying rules immediately after the break,
// which may differ from end of the match. The matching rule may have included
@ -639,6 +642,10 @@ public class RBBIMonkeyTest extends TestFmwk {
initialMatch = false;
}
}
if (expectedBreakCount >= fString.length()) {
throw new IllegalArgumentException(String.format("expectedBreakCount (%d) should be less than the test string length (%d).",
expectedBreakCount, fString.length()));
}
};
// Helper function to find the starting index of a match of the "BreakPosition" named capture group.