TESTCASE_AUTO(Test16BitsTrieWith16BitStateTable);
TESTCASE_AUTO(TestTable_8_16_Bits);
TESTCASE_AUTO(TestBug13590);
+ TESTCASE_AUTO(TestUnpairedSurrogate);
#if U_ENABLE_TRACING
TESTCASE_AUTO(TestTraceCreateCharacter);
}
#endif
+void RBBITest::TestUnpairedSurrogate() {
+ UnicodeString rules(u"ab;");
+
+ UErrorCode status = U_ZERO_ERROR;
+ UParseError pe;
+ RuleBasedBreakIterator bi1(rules, pe, status);
+ assertSuccess(WHERE, status);
+ UnicodeString rtRules = bi1.getRules();
+ // make sure the simple one work first.
+ assertEquals(WHERE, rules, rtRules);
+
+
+ rules = UnicodeString(u"a\\ud800b;").unescape();
+ pe.line = 0;
+ pe.offset = 0;
+ RuleBasedBreakIterator bi2(rules, pe, status);
+ assertEquals(WHERE "unpaired lead surrogate", U_ILLEGAL_CHAR_FOUND , status);
+ if (pe.line != 1 || pe.offset != 1) {
+ errln("pe (line, offset) expected (1, 1), got (%d, %d)", pe.line, pe.offset);
+ }
+
+ status = U_ZERO_ERROR;
+ rules = UnicodeString(u"a\\ude00b;").unescape();
+ pe.line = 0;
+ pe.offset = 0;
+ RuleBasedBreakIterator bi3(rules, pe, status);
+ assertEquals(WHERE "unpaired tail surrogate", U_ILLEGAL_CHAR_FOUND , status);
+ if (pe.line != 1 || pe.offset != 1) {
+ errln("pe (line, offset) expected (1, 1), got (%d, %d)", pe.line, pe.offset);
+ }
+
+ // make sure the surrogate one work too.
+ status = U_ZERO_ERROR;
+ rules = UnicodeString(u"a😀b;");
+ RuleBasedBreakIterator bi4(rules, pe, status);
+ rtRules = bi4.getRules();
+ assertEquals(WHERE, rules, rtRules);
+}
+
#endif // #if !UCONFIG_NO_BREAK_ITERATION
assertEquals("Wrong number of breaks found", 2, breaksFound);
}
+ /* Test handling of unpair surrogate.
+ */
+ @Test
+ public void TestUnpairedSurrogate() {
+ // make sure the simple one work first.
+ String rules = "ab;";
+ RuleBasedBreakIterator bi = new RuleBasedBreakIterator(rules);
+ assertEquals("Rules does not match", rules, bi.toString());
+
+ try {
+ new RuleBasedBreakIterator("a\ud800b;");
+ fail("TestUnpairedSurrogate: RuleBasedBreakIterator() failed to throw an exception with unpair low surrogate.");
+ }
+ catch (IllegalArgumentException e) {
+ // expected exception with unpair surrogate.
+ }
+ catch (Exception e) {
+ fail("TestUnpairedSurrogate: Unexpected exception while new RuleBasedBreakIterator() with unpair low surrogate: " + e);
+ }
+
+ try {
+ new RuleBasedBreakIterator("a\ude00b;");
+ fail("TestUnpairedSurrogate: RuleBasedBreakIterator() failed to throw an exception with unpair high surrogate.");
+ }
+ catch (IllegalArgumentException e) {
+ // expected exception with unpair surrogate.
+ }
+ catch (Exception e) {
+ fail("TestUnpairedSurrogate: Unexpected exception while new RuleBasedBreakIterator() with unpair high surrogate: " + e);
+ }
+
+
+ // make sure the surrogate one work too.
+ rules = "a😀b;";
+ bi = new RuleBasedBreakIterator(rules);
+ assertEquals("Rules does not match", rules, bi.toString());
+ }
}