TESTCASE_AUTO(TestEnglishGB);
TESTCASE_AUTO(TestNynorsk);
TESTCASE_AUTO(TestChineseTradHK);
- TESTCASE_AUTO(TestFieldPositionIteratorWontCrash);
TESTCASE_AUTO(TestFieldPositionIteratorWith1Item);
- TESTCASE_AUTO(TestFieldPositionIteratorWith1ItemAndDataBefore);
TESTCASE_AUTO(TestFieldPositionIteratorWith2Items);
- TESTCASE_AUTO(TestFieldPositionIteratorWith2ItemsAndDataBefore);
TESTCASE_AUTO(TestFieldPositionIteratorWith2ItemsPatternShift);
TESTCASE_AUTO(TestFieldPositionIteratorWith3Items);
- TESTCASE_AUTO(TestFieldPositionIteratorWith3ItemsAndDataBefore);
TESTCASE_AUTO(TestFieldPositionIteratorWith3ItemsPatternShift);
TESTCASE_AUTO(TestFormattedValue);
TESTCASE_AUTO(TestDifferentStyles);
}
} // namespace
-void ListFormatterTest::ExpectPositions(FieldPositionIterator& iter,
- int32_t *values, int32_t tupleCount) {
+void ListFormatterTest::ExpectPositions(
+ const FormattedList& iter,
+ int32_t *values,
+ int32_t tupleCount,
+ UErrorCode& status) {
UBool found[10];
- FieldPosition fp;
+ ConstrainedFieldPosition cfp;
+ cfp.constrainCategory(UFIELD_CATEGORY_LIST);
if (tupleCount > 10) {
assertTrue("internal error, tupleCount too large", FALSE);
} else {
found[i] = FALSE;
}
}
- while (iter.next(fp)) {
+ while (iter.nextPosition(cfp, status)) {
UBool ok = FALSE;
- int32_t id = fp.getField();
- int32_t start = fp.getBeginIndex();
- int32_t limit = fp.getEndIndex();
+ int32_t id = cfp.getField();
+ int32_t start = cfp.getStart();
+ int32_t limit = cfp.getLimit();
char buf[128];
sprintf(buf, "%24s %3d %3d %3d", attrString(id), id, start, limit);
logln(buf);
CheckFourCases("en_GB", one, two, three, four, results, "TestEnglishGB()");
}
-void ListFormatterTest::TestFieldPositionIteratorWontCrash() {
- IcuTestErrorCode errorCode(*this, "TestFieldPositionIteratorWontCrash()");
- LocalPointer<ListFormatter> formatter(
- ListFormatter::createInstance(Locale("en"), errorCode));
- if (U_FAILURE(errorCode)) {
- dataerrln(
- "ListFormatter::createInstance(Locale(\"en\"), errorCode) failed in "
- "TestFieldPositionIteratorWontCrash: %s",
- u_errorName(errorCode));
- return;
- }
- UnicodeString data[3] = {"a", "bbb", "cc"};
- UnicodeString actualResult;
- // make sure NULL as FieldPositionIterator won't caused crash.
- formatter->format(data, 3, actualResult, nullptr, errorCode);
- if (U_FAILURE(errorCode)) {
- dataerrln(
- "ListFormatter::format(data, 3, nullptr, errorCode) "
- "failed in TestFieldPositionIteratorWontCrash: %s",
- u_errorName(errorCode));
- return;
- }
-}
-
void ListFormatterTest::RunTestFieldPositionIteratorWithFormatter(
ListFormatter* formatter,
UnicodeString data[], int32_t n, int32_t expected[], int32_t tupleCount,
- UnicodeString& appendTo, const char16_t *expectedFormatted,
+ const char16_t *expectedFormatted,
const char* testName) {
IcuTestErrorCode errorCode(*this, testName);
- FieldPositionIterator iter;
- formatter->format(data, n, appendTo, &iter, errorCode);
+ FormattedList fl = formatter->formatStringsToValue(data, n, errorCode);
+ UnicodeString actual = fl.toString(errorCode);
if (U_FAILURE(errorCode)) {
dataerrln(
"ListFormatter::format(data, %d, &iter, errorCode) "
"failed in %s: %s", n, testName, u_errorName(errorCode));
return;
}
- if (appendTo != expectedFormatted) {
- errln(UnicodeString("Expected: |") + expectedFormatted + "|, Actual: |" + appendTo + "|");
+ if (actual != expectedFormatted) {
+ errln(UnicodeString("Expected: |") + expectedFormatted + "|, Actual: |" + actual + "|");
}
- ExpectPositions(iter, expected, tupleCount);
+ ExpectPositions(fl, expected, tupleCount, errorCode);
}
void ListFormatterTest::RunTestFieldPositionIteratorWithNItemsPatternShift(
UnicodeString data[], int32_t n, int32_t expected[], int32_t tupleCount,
- UnicodeString& appendTo, const char16_t *expectedFormatted,
+ const char16_t *expectedFormatted,
const char* testName) {
IcuTestErrorCode errorCode(*this, testName);
LocalPointer<ListFormatter> formatter(
}
RunTestFieldPositionIteratorWithFormatter(
formatter.getAlias(),
- data, n, expected, tupleCount, appendTo, expectedFormatted, testName);
+ data, n, expected, tupleCount, expectedFormatted, testName);
}
void ListFormatterTest::RunTestFieldPositionIteratorWithNItems(
UnicodeString data[], int32_t n, int32_t expected[], int32_t tupleCount,
- UnicodeString& appendTo, const char16_t *expectedFormatted,
+ const char16_t *expectedFormatted,
const char* testName) {
IcuTestErrorCode errorCode(*this, testName);
LocalPointer<ListFormatter> formatter(
}
RunTestFieldPositionIteratorWithFormatter(
formatter.getAlias(),
- data, n, expected, tupleCount, appendTo, expectedFormatted, testName);
-}
-
-void ListFormatterTest::TestFieldPositionIteratorWith3ItemsAndDataBefore() {
- // 0 1 2
- // 0123456789012345678901234567
- // "Hello World: a, bbb, and cc"
- UnicodeString data[3] = {"a", "bbb", "cc"};
- int32_t expected[] = {
- ULISTFMT_ELEMENT_FIELD, 13, 14,
- ULISTFMT_LITERAL_FIELD, 14, 16,
- ULISTFMT_ELEMENT_FIELD, 16, 19,
- ULISTFMT_LITERAL_FIELD, 19, 25,
- ULISTFMT_ELEMENT_FIELD, 25, 27
- };
- int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
- UnicodeString appendTo(u"Hello World: ");
- RunTestFieldPositionIteratorWithNItems(
- data, 3, expected, tupleCount, appendTo,
- u"Hello World: a, bbb, and cc",
- "TestFieldPositionIteratorWith3ItemsAndDataBefore");
+ data, n, expected, tupleCount, expectedFormatted, testName);
}
void ListFormatterTest::TestFieldPositionIteratorWith3Items() {
ULISTFMT_ELEMENT_FIELD, 12, 14
};
int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
- UnicodeString appendTo;
RunTestFieldPositionIteratorWithNItems(
- data, 3, expected, tupleCount, appendTo,
+ data, 3, expected, tupleCount,
u"a, bbb, and cc",
"TestFieldPositionIteratorWith3Items");
}
ULISTFMT_ELEMENT_FIELD, 0, 2
};
int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
- UnicodeString appendTo;
RunTestFieldPositionIteratorWithNItemsPatternShift(
- data, 3, expected, tupleCount, appendTo,
+ data, 3, expected, tupleCount,
u"cc bbb a",
"TestFieldPositionIteratorWith3ItemsPatternShift");
}
-void ListFormatterTest::TestFieldPositionIteratorWith2ItemsAndDataBefore() {
- // 0 1
- // 0123456789012345
- // "Foo: bbb and cc"
- UnicodeString data[2] = {"bbb", "cc"};
- int32_t expected[] = {
- ULISTFMT_ELEMENT_FIELD, 5, 8,
- ULISTFMT_LITERAL_FIELD, 8, 13,
- ULISTFMT_ELEMENT_FIELD, 13, 15
- };
- int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
- UnicodeString appendTo("Foo: ");
- RunTestFieldPositionIteratorWithNItems(
- data, 2, expected, tupleCount, appendTo,
- u"Foo: bbb and cc",
- "TestFieldPositionIteratorWith2ItemsAndDataBefore");
-}
-
void ListFormatterTest::TestFieldPositionIteratorWith2Items() {
// 0 1
// 01234567890
ULISTFMT_ELEMENT_FIELD, 8, 10
};
int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
- UnicodeString appendTo;
RunTestFieldPositionIteratorWithNItems(
- data, 2, expected, tupleCount, appendTo,
+ data, 2, expected, tupleCount,
u"bbb and cc",
"TestFieldPositionIteratorWith2Items");
}
ULISTFMT_ELEMENT_FIELD, 0, 2
};
int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
- UnicodeString appendTo;
RunTestFieldPositionIteratorWithNItemsPatternShift(
- data, 2, expected, tupleCount, appendTo,
+ data, 2, expected, tupleCount,
u"cc bbb",
"TestFieldPositionIteratorWith2ItemsPatternShift");
}
-void ListFormatterTest::TestFieldPositionIteratorWith1ItemAndDataBefore() {
- // 012345678
- // "Hello cc"
- UnicodeString data[1] = {"cc"};
- int32_t expected[] = {
- ULISTFMT_ELEMENT_FIELD, 6, 8
- };
- int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
- UnicodeString appendTo("Hello ");
- RunTestFieldPositionIteratorWithNItems(
- data, 1, expected, tupleCount, appendTo,
- u"Hello cc",
- "TestFieldPositionIteratorWith1ItemAndDataBefore");
-}
-
void ListFormatterTest::TestFieldPositionIteratorWith1Item() {
// 012
// "cc"
ULISTFMT_ELEMENT_FIELD, 0, 2
};
int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
- UnicodeString appendTo;
RunTestFieldPositionIteratorWithNItems(
- data, 1, expected, tupleCount, appendTo,
+ data, 1, expected, tupleCount,
u"cc",
"TestFieldPositionIteratorWith1Item");
}