*******************************************************************************
*/
package com.ibm.icu.dev.test.rbbi;
-
+
//Regression testing of RuleBasedBreakIterator
//
// TODO: These tests should be mostly retired.
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
generalIteratorTest(lineIterDefault, linedata);
}
-
+
// =========================================================================
// general test subroutines
// =========================================================================
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) {
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[] = {
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;
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() {
//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 ),
+ "false when comparing to string '0'.");
}
}
-
+
/*
* Tests the method public int first()
*/
// 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()
*/
+ "BreakIterator.DONE when the object has a null fText.");
}
}
-
+
/*
* Tests the method public int following(int offset)
*/
+ "0 when the object has a fText of dummy.");
}
}
-
+
/*
* Tests the method public int preceding(int offset)
*/
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) {
+ "0 when the object has a fText of dummy.");
}
}
-
+
/* Tests the method public int current() */
@Test
public void TestCurrent(){
+ "0 when the object has a fText of dummy.");
}
}
-
+
+ @Test
public void TestBug7547() {
try {
new RuleBasedBreakIterator("");
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());
+ }
+ }
+