X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b331163bffd790ced0e88b73f44f86d49ccc48a5..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/test/intltest/tmsgfmt.cpp diff --git a/icuSources/test/intltest/tmsgfmt.cpp b/icuSources/test/intltest/tmsgfmt.cpp index 939de8c6..df018940 100644 --- a/icuSources/test/intltest/tmsgfmt.cpp +++ b/icuSources/test/intltest/tmsgfmt.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2014, International Business Machines Corporation and + * Copyright (c) 1997-2016, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************** * File TMSGFMT.CPP @@ -67,6 +67,7 @@ TestMessageFormat::runIndexedTest(int32_t index, UBool exec, TESTCASE_AUTO(TestTrimArgumentName); TESTCASE_AUTO(TestSelectOrdinal); TESTCASE_AUTO(TestDecimals); + TESTCASE_AUTO(TestArgIsPrefixOfAnother); TESTCASE_AUTO_END; } @@ -1058,7 +1059,7 @@ void TestMessageFormat::testFormat() { Formattable( UDate(8.71068e+011), Formattable::kIsDate ) }; - const int32_t ft_cnt = sizeof(ftarray) / sizeof(Formattable); + const int32_t ft_cnt = UPRV_LENGTHOF(ftarray); Formattable ft_arr( ftarray, ft_cnt ); Formattable* fmt = new Formattable(UDate(8.71068e+011), Formattable::kIsDate); @@ -1486,7 +1487,7 @@ void TestMessageFormat::TestUnlimitedArgsAndSubformats() { Formattable("of course"), Formattable("Horace"), }; - const int32_t ARGS_LENGTH = sizeof(ARGS) / sizeof(ARGS[0]); + const int32_t ARGS_LENGTH = UPRV_LENGTHOF(ARGS); Formattable ARGS_OBJ(ARGS, ARGS_LENGTH); UnicodeString expected = @@ -1519,17 +1520,17 @@ void TestMessageFormat::TestRBNF(void) { // do not always parse, so do not include them "0", "1", "12", "100", "123", "1001", "123,456", "-17", }; - int32_t values_count = sizeof(values)/sizeof(values[0]); + int32_t values_count = UPRV_LENGTHOF(values); UnicodeString formats[] = { "There are {0,spellout} files to search.", "There are {0,spellout,%simplified} files to search.", "The bogus spellout {0,spellout,%BOGUS} files behaves like the default.", - "This is the {0,ordinal} file to search.", // TODO fix bug, ordinal does not parse + "This is the {0,ordinal} file to search.", "Searching this file will take {0,duration} to complete.", "Searching this file will take {0,duration,%with-words} to complete.", }; - int32_t formats_count = sizeof(formats)/sizeof(formats[0]); + int32_t formats_count = UPRV_LENGTHOF(formats); Formattable args[1]; @@ -1554,16 +1555,14 @@ void TestMessageFormat::TestRBNF(void) { fmt->format(args, 1, result, fp, ec); logln((UnicodeString)"value: " + toString(args[0]) + " --> " + result + UnicodeString(" ec: ") + u_errorName(ec)); - if (i != 3) { // TODO: fix this, for now skip ordinal parsing (format string at index 3) - int32_t count = 0; - Formattable* parseResult = fmt->parse(result, count, ec); - if (count != 1) { - errln((UnicodeString)"parse returned " + count + " args"); - } else if (parseResult[0] != args[0]) { - errln((UnicodeString)"parsed argument " + toString(parseResult[0]) + " != " + toString(args[0])); - } - delete []parseResult; + int32_t count = 0; + Formattable* parseResult = fmt->parse(result, count, ec); + if (count != 1) { + errln((UnicodeString)"parse returned " + count + " args"); + } else if (parseResult[0] != args[0]) { + errln((UnicodeString)"parsed argument " + toString(parseResult[0]) + " != " + toString(args[0])); } + delete []parseResult; } } delete fmt; @@ -1702,7 +1701,7 @@ void TestMessageFormat::testAutoQuoteApostrophe(void) { "'} '{'}'", "'} '{'}''", "'} {{{''", "'} {{{'''", }; - int32_t pattern_count = sizeof(patterns)/sizeof(patterns[0]); + int32_t pattern_count = UPRV_LENGTHOF(patterns); for (int i = 0; i < pattern_count; i += 2) { UErrorCode status = U_ZERO_ERROR; @@ -1963,4 +1962,31 @@ void TestMessageFormat::TestDecimals() { errorCode.reset(); } +void TestMessageFormat::TestArgIsPrefixOfAnother() { + IcuTestErrorCode errorCode(*this, "TestArgIsPrefixOfAnother"); + // Ticket #11952 + MessageFormat mf1("{0,select,a{A}ab{AB}abc{ABC}other{?}}", Locale::getEnglish(), errorCode); + Formattable args[3]; + FieldPosition ignore; + UnicodeString result; + args[0].setString("a"); + assertEquals("a", "A", mf1.format(args, 1, result, ignore, errorCode)); + args[0].setString("ab"); + assertEquals("ab", "AB", mf1.format(args, 1, result.remove(), ignore, errorCode)); + args[0].setString("abc"); + assertEquals("abc", "ABC", mf1.format(args, 1, result.remove(), ignore, errorCode)); + + // Ticket #12172 + MessageFormat mf2("{a} {aa} {aaa}", Locale::getEnglish(), errorCode); + UnicodeString argNames[3] = { "a", "aa", "aaa" }; + args[0].setString("A"); + args[1].setString("AB"); + args[2].setString("ABC"); + assertEquals("a aa aaa", "A AB ABC", mf2.format(argNames, args, 3, result.remove(), errorCode)); + + // Ticket #12172 + MessageFormat mf3("{aa} {aaa}", Locale::getEnglish(), errorCode); + assertEquals("aa aaa", "AB ABC", mf3.format(argNames + 1, args + 1, 2, result.remove(), errorCode)); +} + #endif /* #if !UCONFIG_NO_FORMATTING */