mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-7547 Prohibit RuleBasedBreakIterator construction from empty rules.
X-SVN-Rev: 38741
This commit is contained in:
parent
33e71967fc
commit
04e3a43806
2 changed files with 34 additions and 27 deletions
|
@ -957,6 +957,12 @@ class RBBIRuleScanner {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// If there are no forward rules throw an error.
|
||||
//
|
||||
if (fRB.fTreeRoots[RBBIRuleBuilder.fForwardTree] == null) {
|
||||
error(RBBIRuleBuilder.U_BRK_RULE_SYNTAX);
|
||||
}
|
||||
|
||||
//
|
||||
// If there were NO user specified reverse rules, set up the equivalent of ".*;"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2013, International Business Machines Corporation and
|
||||
* Copyright (C) 1996-2016, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -690,7 +690,7 @@ public class RBBITest extends TestFmwk {
|
|||
|
||||
/* Tests the method public Object clone() */
|
||||
public void TestClone() {
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator("");
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
|
||||
try {
|
||||
rbbi.setText((CharacterIterator) null);
|
||||
if (((RuleBasedBreakIterator) rbbi.clone()).getText() != null)
|
||||
|
@ -705,8 +705,8 @@ public class RBBITest extends TestFmwk {
|
|||
* Tests the method public boolean equals(Object that)
|
||||
*/
|
||||
public void TestEquals() {
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator("");
|
||||
RuleBasedBreakIterator rbbi1 = new RuleBasedBreakIterator("");
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
|
||||
RuleBasedBreakIterator rbbi1 = new RuleBasedBreakIterator(".;");
|
||||
|
||||
// TODO: Tests when "if (fRData != other.fRData && (fRData == null || other.fRData == null))" is true
|
||||
|
||||
|
@ -736,38 +736,26 @@ public class RBBITest extends TestFmwk {
|
|||
+ "false when comparing to string '0'.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests the method public void dump()
|
||||
*/
|
||||
public void TestDump() {
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator("");
|
||||
try {
|
||||
rbbi.dump();
|
||||
errln("RuleBasedBreakIterator.dump() was suppose to return "
|
||||
+ "an exception for a blank RuleBasedBreakIterator object.");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Tests the method public int first()
|
||||
*/
|
||||
public void TestFirst() {
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator("");
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
|
||||
// Tests when "if (fText == null)" is true
|
||||
rbbi.setText((CharacterIterator) null);
|
||||
if (rbbi.first() != BreakIterator.DONE) {
|
||||
errln("RuleBasedBreakIterator.first() was suppose to return "
|
||||
+ "BreakIterator.DONE when the object has a null fText.");
|
||||
}
|
||||
assertEquals("RuleBasedBreakIterator.first()", BreakIterator.DONE, rbbi.first());
|
||||
|
||||
rbbi.setText("abc");
|
||||
assertEquals("RuleBasedBreakIterator.first()", 0, rbbi.first());
|
||||
assertEquals("RuleBasedBreakIterator.next()", 1, rbbi.next());
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests the method public int last()
|
||||
*/
|
||||
public void TestLast() {
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator("");
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
|
||||
// Tests when "if (fText == null)" is true
|
||||
rbbi.setText((CharacterIterator) null);
|
||||
if (rbbi.last() != BreakIterator.DONE) {
|
||||
|
@ -780,7 +768,7 @@ public class RBBITest extends TestFmwk {
|
|||
* Tests the method public int following(int offset)
|
||||
*/
|
||||
public void TestFollowing() {
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator("");
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
|
||||
// Tests when "else if (offset < fText.getBeginIndex())" is true
|
||||
rbbi.setText("dummy");
|
||||
if (rbbi.following(-1) != 0) {
|
||||
|
@ -793,7 +781,7 @@ public class RBBITest extends TestFmwk {
|
|||
* Tests the method public int preceding(int offset)
|
||||
*/
|
||||
public void TestPreceding() {
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator("");
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
|
||||
// Tests when "if (fText == null || offset > fText.getEndIndex())" is true
|
||||
rbbi.setText((CharacterIterator)null);
|
||||
if (rbbi.preceding(-1) != BreakIterator.DONE) {
|
||||
|
@ -811,7 +799,7 @@ public class RBBITest extends TestFmwk {
|
|||
|
||||
/* Tests the method public int current() */
|
||||
public void TestCurrent(){
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator("");
|
||||
RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
|
||||
// Tests when "(fText != null) ? fText.getIndex() : BreakIterator.DONE" is true and false
|
||||
rbbi.setText((CharacterIterator)null);
|
||||
if(rbbi.current() != BreakIterator.DONE){
|
||||
|
@ -824,4 +812,17 @@ public class RBBITest extends TestFmwk {
|
|||
+ "0 when the object has a fText of dummy.");
|
||||
}
|
||||
}
|
||||
|
||||
public void TestBug7547() {
|
||||
try {
|
||||
new RuleBasedBreakIterator("");
|
||||
fail("TestBug7547: RuleBasedBreakIterator constructor failed to throw an exception with empty rules.");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected exception with empty rules.
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("TestBug7547: Unexpected exception while creating RuleBasedBreakIterator: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue