parent
e9755b9774
commit
ce90dfb861
@ -68,11 +68,11 @@ void RBBIAPITest::TestCloneEquals()
|
||||
b |= *bi1 == *bi2;
|
||||
b |= *bi1 == *bi3;
|
||||
if (b) {
|
||||
errln((UnicodeString)"ERROR:1 RBBI's == and != operator failed.");
|
||||
errln("%s:%d ERROR:1 RBBI's == and != operator failed.", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
if(*bi2 == *biequal || *bi2 == *bi1 || *biequal == *bi3)
|
||||
errln((UnicodeString)"ERROR:2 RBBI's == and != operator failed.");
|
||||
errln("%s:%d ERROR:2 RBBI's == and != operator failed.", __FILE__, __LINE__);
|
||||
|
||||
|
||||
// Quick test of RulesBasedBreakIterator assignment -
|
||||
@ -90,15 +90,15 @@ void RBBIAPITest::TestCloneEquals()
|
||||
|
||||
RuleBasedBreakIterator biDefault, biDefault2;
|
||||
if(U_FAILURE(status)){
|
||||
errln((UnicodeString)"FAIL : in construction of default iterator");
|
||||
errln("%s:%d FAIL : in construction of default iterator", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
if (biDefault == *bix) {
|
||||
errln((UnicodeString)"ERROR: iterators should not compare ==");
|
||||
errln("%s:%d ERROR: iterators should not compare ==", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
if (biDefault != biDefault2) {
|
||||
errln((UnicodeString)"ERROR: iterators should compare ==");
|
||||
errln("%s:%d ERROR: iterators should compare ==", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -106,41 +106,41 @@ void RBBIAPITest::TestCloneEquals()
|
||||
UnicodeString HelloString("Hello Kitty");
|
||||
bix->setText(HelloString);
|
||||
if (*bix == *bi2) {
|
||||
errln(UnicodeString("ERROR: strings should not be equal before assignment."));
|
||||
errln("%s:%d ERROR: strings should not be equal before assignment.", __FILE__, __LINE__);
|
||||
}
|
||||
*bix = *bi2;
|
||||
if (*bix != *bi2) {
|
||||
errln(UnicodeString("ERROR: strings should be equal before assignment."));
|
||||
errln("%s:%d ERROR: strings should be equal before assignment.", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
int bixnext = bix->next();
|
||||
int bi2next = bi2->next();
|
||||
if (! (bixnext == bi2next && bixnext == 7)) {
|
||||
errln(UnicodeString("ERROR: iterators behaved differently after assignment."));
|
||||
errln("%s:%d ERROR: iterators behaved differently after assignment.", __FILE__, __LINE__);
|
||||
}
|
||||
delete bix;
|
||||
if (bi2->next() != 8) {
|
||||
errln(UnicodeString("ERROR: iterator.next() failed after deleting copy."));
|
||||
errln("%s:%d ERROR: iterator.next() failed after deleting copy.", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
|
||||
|
||||
logln((UnicodeString)"Testing clone()");
|
||||
RuleBasedBreakIterator* bi1clone=(RuleBasedBreakIterator*)bi1->clone();
|
||||
RuleBasedBreakIterator* bi2clone=(RuleBasedBreakIterator*)bi2->clone();
|
||||
RuleBasedBreakIterator* bi1clone = dynamic_cast<RuleBasedBreakIterator *>(bi1->clone());
|
||||
RuleBasedBreakIterator* bi2clone = dynamic_cast<RuleBasedBreakIterator *>(bi2->clone());
|
||||
|
||||
if(*bi1clone != *bi1 || *bi1clone != *biequal ||
|
||||
*bi1clone == *bi3 || *bi1clone == *bi2)
|
||||
errln((UnicodeString)"ERROR:1 RBBI's clone() method failed");
|
||||
errln("%s:%d ERROR:1 RBBI's clone() method failed", __FILE__, __LINE__);
|
||||
|
||||
if(*bi2clone == *bi1 || *bi2clone == *biequal ||
|
||||
*bi2clone == *bi3 || *bi2clone != *bi2)
|
||||
errln((UnicodeString)"ERROR:2 RBBI's clone() method failed");
|
||||
errln("%s:%d ERROR:2 RBBI's clone() method failed", __FILE__, __LINE__);
|
||||
|
||||
if(bi1->getText() != bi1clone->getText() ||
|
||||
bi2clone->getText() != bi2->getText() ||
|
||||
*bi2clone == *bi1clone )
|
||||
errln((UnicodeString)"ERROR: RBBI's clone() method failed");
|
||||
errln("%s:%d ERROR: RBBI's clone() method failed", __FILE__, __LINE__);
|
||||
|
||||
delete bi1clone;
|
||||
delete bi2clone;
|
||||
@ -427,12 +427,12 @@ void RBBIAPITest::TestIteration()
|
||||
int32_t i;
|
||||
i = bi->first();
|
||||
if (i != 0) {
|
||||
errln("Incorrect value from bi->first(). Expected 0, got %d.", i);
|
||||
errln("%s:%d Incorrect value from bi->first(). Expected 0, got %d.", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
i = bi->last();
|
||||
if (i != 10) {
|
||||
errln("Incorrect value from bi->last(). Expected 10, got %d", i);
|
||||
errln("%s:%d Incorrect value from bi->last(). Expected 10, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
//
|
||||
@ -441,14 +441,14 @@ void RBBIAPITest::TestIteration()
|
||||
bi->last();
|
||||
i = bi->previous();
|
||||
if (i != 9) {
|
||||
errln("Incorrect value from bi->last() at line %d. Expected 9, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->last(). Expected 9, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
|
||||
bi->first();
|
||||
i = bi->previous();
|
||||
if (i != BreakIterator::DONE) {
|
||||
errln("Incorrect value from bi->previous() at line %d. Expected DONE, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->previous(). Expected DONE, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
//
|
||||
@ -457,13 +457,13 @@ void RBBIAPITest::TestIteration()
|
||||
bi->first();
|
||||
i = bi->next();
|
||||
if (i != 1) {
|
||||
errln("Incorrect value from bi->next() at line %d. Expected 1, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->next(). Expected 1, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
bi->last();
|
||||
i = bi->next();
|
||||
if (i != BreakIterator::DONE) {
|
||||
errln("Incorrect value from bi->next() at line %d. Expected DONE, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->next(). Expected DONE, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
|
||||
@ -473,27 +473,27 @@ void RBBIAPITest::TestIteration()
|
||||
bi->first();
|
||||
i = bi->current();
|
||||
if (i != 0) {
|
||||
errln("Incorrect value from bi->previous() at line %d. Expected 0, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->previous(). Expected 0, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
bi->next();
|
||||
i = bi->current();
|
||||
if (i != 1) {
|
||||
errln("Incorrect value from bi->previous() at line %d. Expected 1, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->previous(). Expected 1, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
bi->last();
|
||||
bi->next();
|
||||
i = bi->current();
|
||||
if (i != 10) {
|
||||
errln("Incorrect value from bi->previous() at line %d. Expected 10, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->previous(). Expected 10, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
bi->first();
|
||||
bi->previous();
|
||||
i = bi->current();
|
||||
if (i != 0) {
|
||||
errln("Incorrect value from bi->previous() at line %d. Expected 0, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->previous(). Expected 0, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
|
||||
@ -502,17 +502,17 @@ void RBBIAPITest::TestIteration()
|
||||
//
|
||||
i = bi->following(4);
|
||||
if (i != 5) {
|
||||
errln("Incorrect value from bi->following() at line %d. Expected 5, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->following(). Expected 5, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
i = bi->following(9);
|
||||
if (i != 10) {
|
||||
errln("Incorrect value from bi->following() at line %d. Expected 10, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->following(). Expected 10, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
i = bi->following(10);
|
||||
if (i != BreakIterator::DONE) {
|
||||
errln("Incorrect value from bi->following() at line %d. Expected DONE, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->following(). Expected DONE, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
|
||||
@ -521,22 +521,22 @@ void RBBIAPITest::TestIteration()
|
||||
//
|
||||
i = bi->preceding(4);
|
||||
if (i != 3) {
|
||||
errln("Incorrect value from bi->preceding() at line %d. Expected 3, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->preceding(). Expected 3, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
i = bi->preceding(10);
|
||||
if (i != 9) {
|
||||
errln("Incorrect value from bi->preceding() at line %d. Expected 9, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->preceding(). Expected 9, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
i = bi->preceding(1);
|
||||
if (i != 0) {
|
||||
errln("Incorrect value from bi->preceding() at line %d. Expected 0, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->preceding(). Expected 0, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
i = bi->preceding(0);
|
||||
if (i != BreakIterator::DONE) {
|
||||
errln("Incorrect value from bi->preceding() at line %d. Expected DONE, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->preceding(). Expected DONE, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
|
||||
@ -545,20 +545,20 @@ void RBBIAPITest::TestIteration()
|
||||
//
|
||||
bi->first();
|
||||
if (bi->isBoundary(3) != TRUE) {
|
||||
errln("Incorrect value from bi->isBoudary() at line %d. Expected TRUE, got FALSE", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->isBoudary(). Expected TRUE, got FALSE", __FILE__, __LINE__, i);
|
||||
}
|
||||
i = bi->current();
|
||||
if (i != 3) {
|
||||
errln("Incorrect value from bi->current() at line %d. Expected 3, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->current(). Expected 3, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
|
||||
if (bi->isBoundary(11) != FALSE) {
|
||||
errln("Incorrect value from bi->isBoudary() at line %d. Expected FALSE, got TRUE", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->isBoudary(). Expected FALSE, got TRUE", __FILE__, __LINE__, i);
|
||||
}
|
||||
i = bi->current();
|
||||
if (i != 10) {
|
||||
errln("Incorrect value from bi->current() at line %d. Expected 10, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->current(). Expected 10, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
//
|
||||
@ -567,18 +567,18 @@ void RBBIAPITest::TestIteration()
|
||||
bi->first();
|
||||
i = bi->next(4);
|
||||
if (i != 4) {
|
||||
errln("Incorrect value from bi->next() at line %d. Expected 4, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->next(). Expected 4, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
i = bi->next(6);
|
||||
if (i != 10) {
|
||||
errln("Incorrect value from bi->next() at line %d. Expected 10, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->next(). Expected 10, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
bi->first();
|
||||
i = bi->next(11);
|
||||
if (i != BreakIterator::DONE) {
|
||||
errln("Incorrect value from bi->next() at line %d. Expected BreakIterator::DONE, got %d", __LINE__, i);
|
||||
errln("%s:%d Incorrect value from bi->next(). Expected BreakIterator::DONE, got %d", __FILE__, __LINE__, i);
|
||||
}
|
||||
|
||||
delete bi;
|
||||
@ -666,7 +666,7 @@ void RBBIAPITest::TestRuleStatus() {
|
||||
|
||||
BreakIterator *bi = BreakIterator::createWordInstance(Locale::getEnglish(), status);
|
||||
if(U_FAILURE(status)) {
|
||||
errcheckln(status, "Fail : in construction - %s", u_errorName(status));
|
||||
errcheckln(status, "%s:%d Fail in construction - %s", __FILE__, __LINE__, u_errorName(status));
|
||||
} else {
|
||||
bi->setText(testString1);
|
||||
// First test that the breaks are in the right spots.
|
||||
@ -677,12 +677,12 @@ void RBBIAPITest::TestRuleStatus() {
|
||||
int32_t pos, tag;
|
||||
for (pos = bi->first(); pos != BreakIterator::DONE; pos = bi->next(), i++) {
|
||||
if (pos != bounds1[i]) {
|
||||
errln("FAIL: unexpected word break at postion %d", pos);
|
||||
errln("%s:%d FAIL: unexpected word break at postion %d", __FILE__, __LINE__, pos);
|
||||
break;
|
||||
}
|
||||
tag = bi->getRuleStatus();
|
||||
if (tag < tag_lo[i] || tag >= tag_hi[i]) {
|
||||
errln("FAIL: incorrect tag value %d at position %d", tag, pos);
|
||||
errln("%s:%d FAIL: incorrect tag value %d at position %d", __FILE__, __LINE__, tag, pos);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -703,7 +703,7 @@ void RBBIAPITest::TestRuleStatus() {
|
||||
|
||||
bi = BreakIterator::createLineInstance(Locale::getEnglish(), status);
|
||||
if(U_FAILURE(status)) {
|
||||
errcheckln(status, "failed to create word break iterator. - %s", u_errorName(status));
|
||||
errcheckln(status, "%s:%d failed to create line break iterator. - %s", __FILE__, __LINE__, u_errorName(status));
|
||||
} else {
|
||||
int32_t i = 0;
|
||||
int32_t pos, tag;
|
||||
@ -724,8 +724,8 @@ void RBBIAPITest::TestRuleStatus() {
|
||||
success = FALSE; break;
|
||||
}
|
||||
if (success == FALSE) {
|
||||
errln("Fail: incorrect word break status or position. i=%d, pos=%d, tag=%d",
|
||||
i, pos, tag);
|
||||
errln("%s:%d: incorrect line break status or position. i=%d, pos=%d, tag=%d",
|
||||
__FILE__, __LINE__, i, pos, tag);
|
||||
break;
|
||||
}
|
||||
pos = bi->next();
|
||||
@ -734,7 +734,7 @@ void RBBIAPITest::TestRuleStatus() {
|
||||
if (UBRK_LINE_SOFT >= UBRK_LINE_SOFT_LIMIT ||
|
||||
UBRK_LINE_HARD >= UBRK_LINE_HARD_LIMIT ||
|
||||
(UBRK_LINE_HARD > UBRK_LINE_SOFT && UBRK_LINE_HARD < UBRK_LINE_SOFT_LIMIT)) {
|
||||
errln("UBRK_LINE_* constants from header are inconsistent.");
|
||||
errln("%s:%d UBRK_LINE_* constants from header are inconsistent.", __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
delete bi;
|
||||
|
@ -74,7 +74,6 @@ void RBBITest::runIndexedTest( int32_t index, UBool exec, const char* &name, cha
|
||||
#if !UCONFIG_NO_FILE_IO
|
||||
TESTCASE_AUTO(TestBug4153072);
|
||||
#endif
|
||||
TESTCASE_AUTO(TestStatusReturn);
|
||||
#if !UCONFIG_NO_FILE_IO
|
||||
TESTCASE_AUTO(TestUnicodeFiles);
|
||||
TESTCASE_AUTO(TestEmptyString);
|
||||
@ -266,51 +265,6 @@ RBBITest::RBBITest() {
|
||||
RBBITest::~RBBITest() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
//
|
||||
// Test for status {tag} return value from break rules.
|
||||
// TODO: a more thorough test.
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
void RBBITest::TestStatusReturn() {
|
||||
UnicodeString rulesString1("$Letters = [:L:];\n"
|
||||
"$Numbers = [:N:];\n"
|
||||
"$Letters+{1};\n"
|
||||
"$Numbers+{2};\n"
|
||||
"Help\\ /me\\!{4};\n"
|
||||
"[^$Letters $Numbers];\n"
|
||||
"!.*;\n", -1, US_INV);
|
||||
UnicodeString testString1 = "abc123..abc Help me Help me!";
|
||||
// 01234567890123456789012345678
|
||||
int32_t bounds1[] = {0, 3, 6, 7, 8, 11, 12, 16, 17, 19, 20, 25, 27, 28, -1};
|
||||
int32_t brkStatus[] = {0, 1, 2, 0, 0, 1, 0, 1, 0, 1, 0, 4, 1, 0, -1};
|
||||
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
UParseError parseError;
|
||||
|
||||
LocalPointer <BreakIterator> bi(new RuleBasedBreakIterator(rulesString1, parseError, status));
|
||||
if(U_FAILURE(status)) {
|
||||
dataerrln("%s:%d error in break iterator construction - %s", __FILE__, __LINE__, u_errorName(status));
|
||||
return;
|
||||
}
|
||||
int32_t pos;
|
||||
int32_t i = 0;
|
||||
bi->setText(testString1);
|
||||
for (pos=bi->first(); pos!= BreakIterator::DONE; pos=bi->next()) {
|
||||
if (pos != bounds1[i]) {
|
||||
errln("%s:%d expected break at %d, got %d\n", __FILE__, __LINE__, bounds1[i], pos);
|
||||
break;
|
||||
}
|
||||
|
||||
int tag = bi->getRuleStatus();
|
||||
if (tag != brkStatus[i]) {
|
||||
errln("%s:%d break at %d, expected tag %d, got tag %d\n", __FILE__, __LINE__, pos, brkStatus[i], tag);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void printStringBreaks(UText *tstr, int expected[], int expectedCount) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
@ -1131,7 +1085,6 @@ void RBBITest::TestExtended() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Locale locale("");
|
||||
|
||||
UnicodeString rules;
|
||||
TestParams tp(status);
|
||||
|
||||
RegexMatcher localeMatcher(UNICODE_STRING_SIMPLE("<locale *([\\p{L}\\p{Nd}_@&=-]*) *>"), 0, status);
|
||||
@ -1139,7 +1092,6 @@ void RBBITest::TestExtended() {
|
||||
dataerrln("Failure in file %s, line %d, status = \"%s\"", __FILE__, __LINE__, u_errorName(status));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Open and read the test data file.
|
||||
//
|
||||
@ -1170,7 +1122,8 @@ void RBBITest::TestExtended() {
|
||||
PARSE_COMMENT,
|
||||
PARSE_TAG,
|
||||
PARSE_DATA,
|
||||
PARSE_NUM
|
||||
PARSE_NUM,
|
||||
PARSE_RULES
|
||||
}
|
||||
parseState = PARSE_TAG;
|
||||
|
||||
@ -1181,7 +1134,10 @@ void RBBITest::TestExtended() {
|
||||
int32_t column = 0;
|
||||
int32_t charIdx = 0;
|
||||
|
||||
int32_t tagValue = 0; // The numeric value of a <nnn> tag.
|
||||
int32_t tagValue = 0; // The numeric value of a <nnn> tag.
|
||||
|
||||
UnicodeString rules; // Holds rules from a <rules> ... </rules> block
|
||||
int32_t rulesFirstLine; // Line number of the start of current <rules> block
|
||||
|
||||
for (charIdx = 0; charIdx < len; ) {
|
||||
status = U_ZERO_ERROR;
|
||||
@ -1250,6 +1206,16 @@ void RBBITest::TestExtended() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (testString.compare(charIdx-1, 7, "<rules>") == 0 ||
|
||||
testString.compare(charIdx-1, 10, "<badrules>") == 0) {
|
||||
/// charIdx += 6;
|
||||
charIdx = testString.indexOf(0x3e, charIdx) + 1; // 0x3e == '>'
|
||||
parseState = PARSE_RULES;
|
||||
rules.remove();
|
||||
rulesFirstLine = lineNum;
|
||||
break;
|
||||
}
|
||||
|
||||
// <locale loc_name>
|
||||
localeMatcher.reset(testString);
|
||||
if (localeMatcher.lookingAt(charIdx-1, status)) {
|
||||
@ -1278,6 +1244,35 @@ void RBBITest::TestExtended() {
|
||||
}
|
||||
break;
|
||||
|
||||
case PARSE_RULES:
|
||||
if (testString.compare(charIdx-1, 8, "</rules>") == 0) {
|
||||
charIdx += 7;
|
||||
parseState = PARSE_TAG;
|
||||
delete tp.bi;
|
||||
UParseError pe;
|
||||
tp.bi = new RuleBasedBreakIterator(rules, pe, status);
|
||||
skipTest = U_FAILURE(status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("file rbbitst.txt: %d - Error %s creating break iterator from rules.",
|
||||
rulesFirstLine + pe.line - 1, u_errorName(status));
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (testString.compare(charIdx-1, 11, "</badrules>") == 0) {
|
||||
charIdx += 10;
|
||||
parseState = PARSE_TAG;
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
UParseError pe;
|
||||
RuleBasedBreakIterator bi(rules, pe, ec);
|
||||
if (U_SUCCESS(ec)) {
|
||||
errln("file rbbitst.txt: %d - Expected, but did not get, a failure creating break iterator from rules.",
|
||||
rulesFirstLine + pe.line - 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
rules.append(c);
|
||||
break;
|
||||
|
||||
case PARSE_DATA:
|
||||
if (c == u'•') {
|
||||
int32_t breakIdx = tp.dataToBreak.length();
|
||||
@ -1355,7 +1350,6 @@ void RBBITest::TestExtended() {
|
||||
|
||||
|
||||
|
||||
|
||||
if (testString.compare(charIdx-1, 2, "<>") == 0) {
|
||||
charIdx++;
|
||||
int32_t breakIdx = tp.dataToBreak.length();
|
||||
@ -1469,7 +1463,7 @@ void RBBITest::TestExtended() {
|
||||
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("ICU Error %s while parsing test file at line %d.",
|
||||
errln("ICU Error %s while parsing test file at line %d.",
|
||||
u_errorName(status), lineNum);
|
||||
status = U_ZERO_ERROR;
|
||||
goto end_test; // Stop the test
|
||||
@ -1477,6 +1471,18 @@ void RBBITest::TestExtended() {
|
||||
|
||||
}
|
||||
|
||||
// Reached end of test file. Raise an error if parseState indicates that we are
|
||||
// within a block that should have been terminated.
|
||||
|
||||
if (parseState == PARSE_RULES) {
|
||||
errln("rbbitst.txt:%d <rules> block beginning at line %d is not closed.",
|
||||
lineNum, rulesFirstLine);
|
||||
}
|
||||
if (parseState == PARSE_DATA) {
|
||||
errln("rbbitst.txt:%d <data> block not closed.", lineNum);
|
||||
}
|
||||
|
||||
|
||||
end_test:
|
||||
delete [] testFile;
|
||||
#endif
|
||||
@ -3762,16 +3768,16 @@ static void testBreakBoundPreceding(RBBITest *test, UnicodeString ustr,
|
||||
for (i = bi->first(); i != BreakIterator::DONE; i = bi->next()) {
|
||||
forward[count] = i;
|
||||
if (count < expectedcount && expected[count] != i) {
|
||||
test->errln("break forward test failed: expected %d but got %d",
|
||||
expected[count], i);
|
||||
test->errln("%s:%d break forward test failed: expected %d but got %d",
|
||||
__FILE__, __LINE__, expected[count], i);
|
||||
break;
|
||||
}
|
||||
count ++;
|
||||
}
|
||||
if (count != expectedcount) {
|
||||
printStringBreaks(ustr, expected, expectedcount);
|
||||
test->errln("break forward test failed: missed %d match",
|
||||
expectedcount - count);
|
||||
test->errln("%s:%d break forward test failed: missed %d match",
|
||||
__FILE__, __LINE__, expectedcount - count);
|
||||
return;
|
||||
}
|
||||
// testing boundaries
|
||||
@ -3779,13 +3785,15 @@ static void testBreakBoundPreceding(RBBITest *test, UnicodeString ustr,
|
||||
int j = expected[i - 1];
|
||||
if (!bi->isBoundary(j)) {
|
||||
printStringBreaks(ustr, expected, expectedcount);
|
||||
test->errln("isBoundary() failed. Expected boundary at position %d", j);
|
||||
test->errln("%s:%d isBoundary() failed. Expected boundary at position %d",
|
||||
__FILE__, __LINE__, j);
|
||||
return;
|
||||
}
|
||||
for (j = expected[i - 1] + 1; j < expected[i]; j ++) {
|
||||
if (bi->isBoundary(j)) {
|
||||
printStringBreaks(ustr, expected, expectedcount);
|
||||
test->errln("isBoundary() failed. Not expecting boundary at position %d", j);
|
||||
test->errln("%s:%d isBoundary() failed. Not expecting boundary at position %d",
|
||||
__FILE__, __LINE__, j);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -3795,8 +3803,8 @@ static void testBreakBoundPreceding(RBBITest *test, UnicodeString ustr,
|
||||
count --;
|
||||
if (forward[count] != i) {
|
||||
printStringBreaks(ustr, expected, expectedcount);
|
||||
test->errln("happy break test previous() failed: expected %d but got %d",
|
||||
forward[count], i);
|
||||
test->errln("%s:%d happy break test previous() failed: expected %d but got %d",
|
||||
__FILE__, __LINE__, forward[count], i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -3811,9 +3819,12 @@ static void testBreakBoundPreceding(RBBITest *test, UnicodeString ustr,
|
||||
// int j = expected[i] + 1;
|
||||
int j = ustr.moveIndex32(expected[i], 1);
|
||||
for (; j <= expected[i + 1]; j ++) {
|
||||
if (bi->preceding(j) != expected[i]) {
|
||||
int32_t expectedPreceding = expected[i];
|
||||
int32_t actualPreceding = bi->preceding(j);
|
||||
if (actualPreceding != expectedPreceding) {
|
||||
printStringBreaks(ustr, expected, expectedcount);
|
||||
test->errln("preceding(): Not expecting boundary at position %d", j);
|
||||
test->errln("%s:%d preceding(%d): expected %d, got %d",
|
||||
__FILE__, __LINE__, j, expectedPreceding, actualPreceding);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -3905,7 +3916,12 @@ void RBBITest::TestWordBoundary(void)
|
||||
Locale locale("en");
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
// BreakIterator *bi = BreakIterator::createCharacterInstance(locale, status);
|
||||
BreakIterator *bi = BreakIterator::createWordInstance(locale, status);
|
||||
LocalPointer<BreakIterator> bi(BreakIterator::createWordInstance(locale, status), status);
|
||||
if (U_FAILURE(status)) {
|
||||
errcheckln(status, "%s:%d Creation of break iterator failed %s",
|
||||
__FILE__, __LINE__, u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UChar str[50];
|
||||
static const char *strlist[] =
|
||||
{
|
||||
@ -3940,43 +3956,44 @@ void RBBITest::TestWordBoundary(void)
|
||||
"\\u003b\\u0027\\u00b7\\u47a3",
|
||||
};
|
||||
int loop;
|
||||
if (U_FAILURE(status)) {
|
||||
errcheckln(status, "Creation of break iterator failed %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
for (loop = 0; loop < UPRV_LENGTHOF(strlist); loop ++) {
|
||||
// printf("looping %d\n", loop);
|
||||
u_unescape(strlist[loop], str, 20);
|
||||
u_unescape(strlist[loop], str, UPRV_LENGTHOF(str));
|
||||
UnicodeString ustr(str);
|
||||
int forward[50];
|
||||
int count = 0;
|
||||
|
||||
bi->setText(ustr);
|
||||
int prev = 0;
|
||||
int i;
|
||||
for (i = bi->first(); i != BreakIterator::DONE; i = bi->next()) {
|
||||
forward[count ++] = i;
|
||||
if (i > prev) {
|
||||
int j;
|
||||
for (j = prev + 1; j < i; j ++) {
|
||||
if (bi->isBoundary(j)) {
|
||||
printStringBreaks(ustr, forward, count);
|
||||
errln("happy boundary test failed: expected %d not a boundary",
|
||||
j);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bi->isBoundary(i)) {
|
||||
printStringBreaks(ustr, forward, count);
|
||||
errln("happy boundary test failed: expected %d a boundary",
|
||||
i);
|
||||
int prev = -1;
|
||||
for (int32_t boundary = bi->first(); boundary != BreakIterator::DONE; boundary = bi->next()) {
|
||||
++count;
|
||||
if (count >= UPRV_LENGTHOF(forward)) {
|
||||
errln("%s:%d too many breaks found. (loop, count, boundary) = (%d, %d, %d)",
|
||||
__FILE__, __LINE__, loop, count, boundary);
|
||||
return;
|
||||
}
|
||||
prev = i;
|
||||
forward[count] = boundary;
|
||||
if (boundary <= prev) {
|
||||
errln("%s:%d bi::next() did not advance. (loop, prev, boundary) = (%d, %d, %d)\n",
|
||||
__FILE__, __LINE__, loop, prev, boundary);
|
||||
break;
|
||||
}
|
||||
for (int32_t nonBoundary = prev + 1; nonBoundary < boundary; nonBoundary ++) {
|
||||
if (bi->isBoundary(nonBoundary)) {
|
||||
printStringBreaks(ustr, forward, count);
|
||||
errln("%s:%d isBoundary(nonBoundary) failed. (loop, prev, nonBoundary, boundary) = (%d, %d, %d, %d)",
|
||||
__FILE__, __LINE__, loop, prev, nonBoundary, boundary);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!bi->isBoundary(boundary)) {
|
||||
printStringBreaks(ustr, forward, count);
|
||||
errln("%s:%d happy boundary test failed: expected %d a boundary",
|
||||
__FILE__, __LINE__, boundary);
|
||||
return;
|
||||
}
|
||||
prev = boundary;
|
||||
}
|
||||
}
|
||||
delete bi;
|
||||
}
|
||||
|
||||
void RBBITest::TestLineBreaks(void)
|
||||
|
@ -41,11 +41,6 @@ public:
|
||||
|
||||
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL );
|
||||
|
||||
/**
|
||||
* Tests rule status return values
|
||||
**/
|
||||
void TestStatusReturn();
|
||||
|
||||
void TestEmptyString();
|
||||
void TestGetAvailableLocales();
|
||||
void TestGetDisplayName();
|
||||
|
62
icu4c/source/test/testdata/rbbitst.txt
vendored
62
icu4c/source/test/testdata/rbbitst.txt
vendored
@ -14,7 +14,9 @@
|
||||
# <sent> any following data is for sentence break testing
|
||||
# <line> any following data is for line break testing
|
||||
# <char> any following data is for char break testing
|
||||
# <locale local_name> Switch to the named locale at the next occurence of <word>, <sent>, etc.
|
||||
# <rules> rules ... </rules> following data is tested against these rules.
|
||||
# Applies until a following occurence of <word>, <sent>, etc. or another <rules>
|
||||
# <locale locale_name> Switch to the named locale at the next occurence of <word>, <sent>, etc.
|
||||
# <data> ... </data> test data. May span multiple lines.
|
||||
# <> Break position, status == 0
|
||||
# • Break position, status == 0 (Bullet, \u2022)
|
||||
@ -37,8 +39,17 @@
|
||||
# Temp debugging tests
|
||||
<locale en>
|
||||
<word>
|
||||
<data><0>1•2•3•4•</data>
|
||||
# <data><0>ク<400>ライアン<400>トサーバー<400></data>
|
||||
<data><0>コンピューター<400>は<400>、<0>本質<400>的<400>に<400>は<400>数字<400>しか<400>扱う<400>こと<400>が<400>でき<400>ま<400>せん<400>。<0>\
|
||||
コンピューター<400>は<400>、<0>文字<400>や<400>記号<400>など<400>の<400>それぞれに<400>番号<400>を<400>割り振る<400>こと<400>によって<400>扱える<400>\
|
||||
よう<400>にし<400>ます<400>。<0>ユニ<400>コード<400>が<400>出来る<400>まで<400>は<400>、<0>これらの<400>番号<400>を<400>割り振る<400>仕組み<400>が<400>\
|
||||
何<400>百<400>種類<400>も<400>存在<400>しま<400>した<400>。<0>どの<400>一つ<400>を<400>とっても<400>、<0>十分<400>な<400>文字<400>を<400>含<400>\
|
||||
んで<400>は<400>いま<400>せん<400>で<400>した<400>。<0>例えば<400>、<0>欧州<400>連合<400>一つ<400>を<400>見<400>て<400>も<400>、<0>その<400>\
|
||||
すべて<400>の<400>言語<400>を<400>カバー<400>する<400>ため<400>に<400>は<400>、<0>いくつか<400>の<400>異なる<400>符号<400>化<400>の<400>仕組み<400>\
|
||||
が<400>必要<400>で<400>した<400>。<0>英語<400>の<400>よう<400>な<400>一つ<400>の<400>言語<400>に<400>限<400>って<400>も<400>、<0>一つ<400>だけ<400>\
|
||||
の<400>符号<400>化<400>の<400>仕組み<400>では<400>、<0>一般<400>的<400>に<400>使<400>われる<400>すべて<400>の<400>文字<400>、<0>句読点<400>、<0>\
|
||||
。<0></data>
|
||||
|
||||
#<data><0>コンピューター<400>は<400>、<0>本質<400>的<400>に<400>は<400>数字<400>しか<400>扱う<400>こと<400>が<400>でき<400>ま<400>せん<400>。<0>\
|
||||
|
||||
## FILTERED BREAK TESTS
|
||||
|
||||
@ -1308,3 +1319,48 @@ Bangkok)•</data>
|
||||
<data>•\U0001F468\u200D\u2695\uFE0F•\U0001F468\u200D\u2695•\U0001F468\U0001F3FD\u200D\u2695\uFE0F•\U0001F468\U0001F3FD\u200D\u2695\u0020•</data>
|
||||
# woman astronaut, woman astronaut / fitz4
|
||||
<data>•\U0001F469\u200D\U0001F680•\U0001F469\U0001F3FD\u200D\U0001F680\u0020•</data>
|
||||
|
||||
|
||||
####################################################################################
|
||||
#
|
||||
# Test rule status values
|
||||
#
|
||||
####################################################################################
|
||||
<rules> $Letters = [:L:];
|
||||
$Numbers = [:N:];
|
||||
$Letters+{1};
|
||||
$Numbers+{2};
|
||||
Help\ me\!{4};
|
||||
[^$Letters $Numbers];
|
||||
!.*;
|
||||
</rules>
|
||||
<data>•abc<1>123<2>.•.•abc<1> •Help<1> •me<1> •Help me!<4></data>
|
||||
|
||||
# Test option to prohibit unquoted literals.
|
||||
|
||||
<rules>
|
||||
!!forward;
|
||||
Hello\ World;
|
||||
!!reverse;
|
||||
.*;
|
||||
</rules>
|
||||
<data>•Hello World•</data>
|
||||
|
||||
<badrules>
|
||||
!!quoted_literals_only;
|
||||
!!forward;
|
||||
Hello\ World;
|
||||
!!reverse;
|
||||
.*;
|
||||
</badrules>
|
||||
|
||||
<rules>
|
||||
#TODO: uncomment this line when quoted_literals_only is implemented.
|
||||
#!!quoted_literals_only;
|
||||
!!forward;
|
||||
'Hello World';
|
||||
!!reverse;
|
||||
.*;
|
||||
</rules>
|
||||
<data>•Hello World•</data>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user