ICU-9294 test & fix MessageFormat::getFormatNames()
X-SVN-Rev: 32540
This commit is contained in:
parent
62b9d2f4b1
commit
49d407d984
@ -851,7 +851,7 @@ MessageFormat::getFormatNames(UErrorCode& status) {
|
||||
fFormatNames->setDeleter(uprv_deleteUObject);
|
||||
|
||||
for (int32_t partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
|
||||
fFormatNames->addElement(new UnicodeString(getArgName(partIndex)), status);
|
||||
fFormatNames->addElement(new UnicodeString(getArgName(partIndex + 1)), status);
|
||||
}
|
||||
|
||||
StringEnumeration* nameEnumerator = new FormatNameEnumeration(fFormatNames, status);
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "unicode/format.h"
|
||||
#include "unicode/decimfmt.h"
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/msgfmt.h"
|
||||
#include "unicode/numfmt.h"
|
||||
@ -63,6 +64,7 @@ TestMessageFormat::runIndexedTest(int32_t index, UBool exec,
|
||||
TESTCASE_AUTO(TestApostropheMode);
|
||||
TESTCASE_AUTO(TestCompatibleApostrophe);
|
||||
TESTCASE_AUTO(testCoverage);
|
||||
TESTCASE_AUTO(testGetFormatNames);
|
||||
TESTCASE_AUTO(TestTrimArgumentName);
|
||||
TESTCASE_AUTO(TestSelectOrdinal);
|
||||
TESTCASE_AUTO_END;
|
||||
@ -1792,6 +1794,51 @@ void TestMessageFormat::testCoverage(void) {
|
||||
delete msgfmt;
|
||||
}
|
||||
|
||||
void TestMessageFormat::testGetFormatNames() {
|
||||
IcuTestErrorCode errorCode(*this, "testGetFormatNames");
|
||||
MessageFormat msgfmt("Hello, {alice,number} {oops,date,full} {zip,spellout} World.", Locale::getRoot(), errorCode);
|
||||
if(errorCode.logIfFailureAndReset("MessageFormat() failed")) {
|
||||
return;
|
||||
}
|
||||
LocalPointer<StringEnumeration> names(msgfmt.getFormatNames(errorCode));
|
||||
if(errorCode.logIfFailureAndReset("msgfmt.getFormatNames() failed")) {
|
||||
return;
|
||||
}
|
||||
const UnicodeString *name;
|
||||
name = names->snext(errorCode);
|
||||
if (name == NULL || errorCode.isFailure()) {
|
||||
errln("msgfmt.getFormatNames()[0] failed: %s", errorCode.errorName());
|
||||
errorCode.reset();
|
||||
return;
|
||||
}
|
||||
if (!assertEquals("msgfmt.getFormatNames()[0]", UNICODE_STRING_SIMPLE("alice"), *name)) {
|
||||
return;
|
||||
}
|
||||
name = names->snext(errorCode);
|
||||
if (name == NULL || errorCode.isFailure()) {
|
||||
errln("msgfmt.getFormatNames()[1] failed: %s", errorCode.errorName());
|
||||
errorCode.reset();
|
||||
return;
|
||||
}
|
||||
if (!assertEquals("msgfmt.getFormatNames()[1]", UNICODE_STRING_SIMPLE("oops"), *name)) {
|
||||
return;
|
||||
}
|
||||
name = names->snext(errorCode);
|
||||
if (name == NULL || errorCode.isFailure()) {
|
||||
errln("msgfmt.getFormatNames()[2] failed: %s", errorCode.errorName());
|
||||
errorCode.reset();
|
||||
return;
|
||||
}
|
||||
if (!assertEquals("msgfmt.getFormatNames()[2]", UNICODE_STRING_SIMPLE("zip"), *name)) {
|
||||
return;
|
||||
}
|
||||
name = names->snext(errorCode);
|
||||
if (name != NULL) {
|
||||
errln(UnicodeString("msgfmt.getFormatNames()[3] should be NULL but is: ") + *name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void TestMessageFormat::TestTrimArgumentName() {
|
||||
// ICU 4.8 allows and ignores white space around argument names and numbers.
|
||||
IcuTestErrorCode errorCode(*this, "TestTrimArgumentName");
|
||||
|
@ -113,12 +113,11 @@ public:
|
||||
void testAdopt(void);
|
||||
void TestTurkishCasing(void);
|
||||
void testAutoQuoteApostrophe(void);
|
||||
void testCoverage();
|
||||
void testGetFormatNames();
|
||||
void TestTrimArgumentName();
|
||||
void TestSelectOrdinal();
|
||||
|
||||
/* Provide better code coverage */
|
||||
void testCoverage(void);
|
||||
|
||||
private:
|
||||
UnicodeString GetPatternAndSkipSyntax(const MessagePattern& pattern);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user