mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-20 20:19:32 +00:00
ICU-12797 RBBI rule compiler fix.
X-SVN-Rev: 39431
This commit is contained in:
parent
4293df728e
commit
4e22ce5dc8
2 changed files with 42 additions and 31 deletions
|
@ -172,8 +172,6 @@ class RBBINode {
|
|||
n.fRightChild.fParent = n;
|
||||
}
|
||||
}
|
||||
n.fRuleRoot = this.fRuleRoot;
|
||||
n.fChainIn = this.fChainIn;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -199,8 +197,9 @@ class RBBINode {
|
|||
//-------------------------------------------------------------------------
|
||||
RBBINode flattenVariables() {
|
||||
if (fType == varRef) {
|
||||
RBBINode retNode = fLeftChild.cloneTree();
|
||||
// delete this;
|
||||
RBBINode retNode = fLeftChild.cloneTree();
|
||||
retNode.fRuleRoot = this.fRuleRoot;
|
||||
retNode.fChainIn = this.fChainIn;
|
||||
return retNode;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.rbbi;
|
||||
|
||||
|
||||
//Regression testing of RuleBasedBreakIterator
|
||||
//
|
||||
// TODO: These tests should be mostly retired.
|
||||
|
@ -27,10 +27,10 @@ import com.ibm.icu.text.BreakIterator;
|
|||
import com.ibm.icu.text.RuleBasedBreakIterator;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class RBBITest extends TestFmwk {
|
||||
public class RBBITest extends TestFmwk {
|
||||
public RBBITest() {
|
||||
}
|
||||
|
||||
|
||||
private static final String halfNA = "\u0928\u094d\u200d"; /*
|
||||
* halfform NA = devanigiri NA + virama(supresses
|
||||
* inherent vowel)+ zero width joiner
|
||||
|
@ -255,7 +255,7 @@ public class RBBITest extends TestFmwk {
|
|||
generalIteratorTest(lineIterDefault, linedata);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// general test subroutines
|
||||
// =========================================================================
|
||||
|
@ -513,31 +513,31 @@ public class RBBITest extends TestFmwk {
|
|||
out.append(c);
|
||||
else {
|
||||
out.append("\\u");
|
||||
temp = Integer.toHexString((int)c);
|
||||
temp = Integer.toHexString(c);
|
||||
out.append(zeros.substring(0, 4 - temp.length()));
|
||||
out.append(temp);
|
||||
}
|
||||
}
|
||||
logln(out.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestThaiDictionaryBreakIterator() {
|
||||
int position;
|
||||
int index;
|
||||
int result[] = { 1, 2, 5, 10, 11, 12, 11, 10, 5, 2, 1, 0 };
|
||||
char ctext[] = {
|
||||
char ctext[] = {
|
||||
0x0041, 0x0020,
|
||||
0x0E01, 0x0E32, 0x0E23, 0x0E17, 0x0E14, 0x0E25, 0x0E2D, 0x0E07,
|
||||
0x0020, 0x0041
|
||||
};
|
||||
String text = new String(ctext);
|
||||
|
||||
|
||||
ULocale locale = ULocale.createCanonical("th");
|
||||
BreakIterator b = BreakIterator.getWordInstance(locale);
|
||||
|
||||
|
||||
b.setText(text);
|
||||
|
||||
|
||||
index = 0;
|
||||
// Test forward iteration
|
||||
while ((position = b.next())!= BreakIterator.DONE) {
|
||||
|
@ -545,18 +545,18 @@ public class RBBITest extends TestFmwk {
|
|||
errln("Error with ThaiDictionaryBreakIterator forward iteration test at " + position + ".\nShould have been " + result[index-1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Test backward iteration
|
||||
while ((position = b.previous())!= BreakIterator.DONE) {
|
||||
if (position != result[index++]) {
|
||||
errln("Error with ThaiDictionaryBreakIterator backward iteration test at " + position + ".\nShould have been " + result[index-1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Test invalid sequence and spaces
|
||||
char text2[] = {
|
||||
0x0E01, 0x0E39, 0x0020, 0x0E01, 0x0E34, 0x0E19, 0x0E01, 0x0E38, 0x0E49, 0x0E07, 0x0020, 0x0E1B,
|
||||
0x0E34, 0x0E49, 0x0E48, 0x0E07, 0x0E2D, 0x0E22, 0x0E39, 0x0E48, 0x0E43, 0x0E19,
|
||||
0x0E01, 0x0E39, 0x0020, 0x0E01, 0x0E34, 0x0E19, 0x0E01, 0x0E38, 0x0E49, 0x0E07, 0x0020, 0x0E1B,
|
||||
0x0E34, 0x0E49, 0x0E48, 0x0E07, 0x0E2D, 0x0E22, 0x0E39, 0x0E48, 0x0E43, 0x0E19,
|
||||
0x0E16, 0x0E49, 0x0E33
|
||||
};
|
||||
int expectedWordResult[] = {
|
||||
|
@ -573,7 +573,7 @@ public class RBBITest extends TestFmwk {
|
|||
errln("Incorrect break given by thai word break iterator. Expected: " + expectedWordResult[index-1] + " Got: " + position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
brk = BreakIterator.getLineInstance(new ULocale("th"));
|
||||
brk.setText(new String(text2));
|
||||
position = index = 0;
|
||||
|
@ -594,8 +594,8 @@ public class RBBITest extends TestFmwk {
|
|||
errln("Error: Since getRuleStatusVec is not supported in DictionaryBasedBreakIterator, it should return 1 and fillInArray[0] == 0.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: Move these test cases to rbbitst.txt if they aren't there already, then remove this test. It is redundant.
|
||||
@Test
|
||||
public void TestTailoredBreaks() {
|
||||
|
@ -685,7 +685,7 @@ public class RBBITest extends TestFmwk {
|
|||
//final int[] thCharROffsets = { 1, 3, 5, 6, 7, 8, 9, 11,
|
||||
// 12, 13, 15, 17, 19, 20, 22, 24, 26, 27, 28,
|
||||
// 29, 32, 33, 35, 37, 38, 40, 41 };
|
||||
|
||||
|
||||
final TBItem[] tests = {
|
||||
new TBItem( BreakIterator.KIND_SENTENCE, new ULocale("el"), elSentText, elSentTOffsets ),
|
||||
new TBItem( BreakIterator.KIND_SENTENCE, ULocale.ROOT, elSentText, elSentROffsets ),
|
||||
|
@ -747,7 +747,7 @@ public class RBBITest extends TestFmwk {
|
|||
+ "false when comparing to string '0'.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Tests the method public int first()
|
||||
*/
|
||||
|
@ -757,12 +757,12 @@ public class RBBITest extends TestFmwk {
|
|||
// Tests when "if (fText == null)" is true
|
||||
rbbi.setText((CharacterIterator) null);
|
||||
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()
|
||||
*/
|
||||
|
@ -776,7 +776,7 @@ public class RBBITest extends TestFmwk {
|
|||
+ "BreakIterator.DONE when the object has a null fText.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Tests the method public int following(int offset)
|
||||
*/
|
||||
|
@ -790,7 +790,7 @@ public class RBBITest extends TestFmwk {
|
|||
+ "0 when the object has a fText of dummy.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Tests the method public int preceding(int offset)
|
||||
*/
|
||||
|
@ -803,7 +803,7 @@ public class RBBITest extends TestFmwk {
|
|||
errln("RuleBasedBreakIterator.preceding(-1) was suppose to return "
|
||||
+ "0 when the object has a fText of null.");
|
||||
}
|
||||
|
||||
|
||||
// Tests when "else if (offset < fText.getBeginIndex())" is true
|
||||
rbbi.setText("dummy");
|
||||
if (rbbi.preceding(-1) != 0) {
|
||||
|
@ -811,7 +811,7 @@ public class RBBITest extends TestFmwk {
|
|||
+ "0 when the object has a fText of dummy.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Tests the method public int current() */
|
||||
@Test
|
||||
public void TestCurrent(){
|
||||
|
@ -828,7 +828,8 @@ public class RBBITest extends TestFmwk {
|
|||
+ "0 when the object has a fText of dummy.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestBug7547() {
|
||||
try {
|
||||
new RuleBasedBreakIterator("");
|
||||
|
@ -841,4 +842,15 @@ public class RBBITest extends TestFmwk {
|
|||
fail("TestBug7547: Unexpected exception while creating RuleBasedBreakIterator: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestBug12797() {
|
||||
String rules = "!!chain; !!forward; $v=b c; a b; $v; !!reverse; .*;";
|
||||
RuleBasedBreakIterator bi = new RuleBasedBreakIterator(rules);
|
||||
|
||||
bi.setText("abc");
|
||||
bi.first();
|
||||
assertEquals("Rule chaining test", 3, bi.next());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue