From 9be84eb03c9e6f0b961854b9234ad34f354096c6 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Mon, 7 May 2018 23:54:36 +0000 Subject: [PATCH] ICU-11626 port NumberFormatTest.TestCurrencyPluralInfoAndCustomPluralRules to C++ X-SVN-Rev: 41349 --- icu4c/source/test/intltest/numfmtst.cpp | 22 ++++++++++++++++++++++ icu4c/source/test/intltest/numfmtst.h | 1 + 2 files changed, 23 insertions(+) diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 9ab39ebbee0..e020231affc 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -15,6 +15,7 @@ #if !UCONFIG_NO_FORMATTING #include "numfmtst.h" +#include "unicode/currpinf.h" #include "unicode/dcfmtsym.h" #include "unicode/decimfmt.h" #include "unicode/localpointer.h" @@ -671,6 +672,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n TESTCASE_AUTO(Test10354); TESTCASE_AUTO(Test11645_ApplyPatternEquality); TESTCASE_AUTO(Test12567); + TESTCASE_AUTO(TestCurrencyPluralInfoAndCustomPluralRules); TESTCASE_AUTO(Test13056_GroupingSize); TESTCASE_AUTO(Test11025_CurrencyPadding); TESTCASE_AUTO(Test11648_ExpDecFormatMalPattern); @@ -9385,6 +9387,26 @@ void NumberFormatTest::Test12567() { assertTrue("df2 != df1", *df2 != *df1); } +void NumberFormatTest::TestCurrencyPluralInfoAndCustomPluralRules() { + IcuTestErrorCode errorCode(*this, "TestCurrencyPluralInfoAndCustomPluralRules"); + // Ticket #11626: No unit test demonstrating how to use CurrencyPluralInfo to + // change formatting spelled out currencies + LocalPointer symbols( + new DecimalFormatSymbols(Locale::getEnglish(), errorCode)); + CurrencyPluralInfo info(Locale::getEnglish(), errorCode); + info.setCurrencyPluralPattern(u"one", u"0 qwerty", errorCode); + info.setCurrencyPluralPattern(u"few", u"0 dvorak", errorCode); + info.setPluralRules(u"one: n is 1; few: n in 2..4", errorCode); + DecimalFormat df(u"#", symbols.orphan(), UNUM_CURRENCY_PLURAL, errorCode); + df.setCurrencyPluralInfo(info); + df.setCurrency(u"USD"); + + UnicodeString result; + // TODO(shane): assertEquals("Plural one", u"1.00 qwerty", df.format(1, result, errorCode)); + // TODO(shane): assertEquals("Plural few", u"3.00 dvorak", df.format(3, result.remove(), errorCode)); + assertEquals("Plural other", u"5.80 US dollars", df.format(5.8, result.remove(), errorCode)); +} + void NumberFormatTest::Test13056_GroupingSize() { UErrorCode status = U_ZERO_ERROR; DecimalFormat df(u"#,##0", status); diff --git a/icu4c/source/test/intltest/numfmtst.h b/icu4c/source/test/intltest/numfmtst.h index a9b4f4cc374..03592dc0016 100644 --- a/icu4c/source/test/intltest/numfmtst.h +++ b/icu4c/source/test/intltest/numfmtst.h @@ -236,6 +236,7 @@ class NumberFormatTest: public CalendarTimeZoneTest { void Test10354(); void Test11645_ApplyPatternEquality(); void Test12567(); + void TestCurrencyPluralInfoAndCustomPluralRules(); void Test13056_GroupingSize(); void Test11025_CurrencyPadding(); void Test11648_ExpDecFormatMalPattern(); -- 2.40.0