From 28e9f693789012c0c1d2085fcccf4513095e7380 Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Sat, 28 Apr 2018 07:27:02 +0000 Subject: [PATCH] ICU-11897 Adding tests for localized pattern separator symbol. X-SVN-Rev: 41292 --- icu4c/source/test/intltest/numfmtst.cpp | 14 ++++++++++++++ icu4c/source/test/intltest/numfmtst.h | 1 + .../ibm/icu/dev/test/format/NumberFormatTest.java | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 2dbc30ddaed..2c504b26cd6 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -661,6 +661,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n TESTCASE_AUTO(TestMultiplierWithScale); TESTCASE_AUTO(TestFastFormatInt32); TESTCASE_AUTO(TestParseNaN); + TESTCASE_AUTO(Test11897_LocalizedPatternSeparator); TESTCASE_AUTO_END; } @@ -9134,4 +9135,17 @@ void NumberFormatTest::TestParseNaN() { assertEquals("NaN should round-trip", u"NaN", formatResult); } +void NumberFormatTest::Test11897_LocalizedPatternSeparator() { + IcuTestErrorCode status(*this, "Test11897_LocalizedPatternSeparator"); + + DecimalFormatSymbols dfs("en", status); + dfs.setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, u"!", FALSE); + DecimalFormat df(u"0", dfs, status); + df.applyPattern("a0;b0", status); // should not throw + UnicodeString result; + assertEquals("should apply the normal pattern", df.getNegativePrefix(result.remove()), "b"); + df.applyLocalizedPattern(u"c0!d0", status); // should not throw + assertEquals("should apply the localized pattern", df.getNegativePrefix(result.remove()), "d"); +} + #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/test/intltest/numfmtst.h b/icu4c/source/test/intltest/numfmtst.h index 3239619bfcc..3f97bc682c2 100644 --- a/icu4c/source/test/intltest/numfmtst.h +++ b/icu4c/source/test/intltest/numfmtst.h @@ -226,6 +226,7 @@ class NumberFormatTest: public CalendarTimeZoneTest { void TestMultiplierWithScale(); void TestFastFormatInt32(); void TestParseNaN(); + void Test11897_LocalizedPatternSeparator(); private: UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f); diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java index 3cd2cc6dba4..796d116de78 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java @@ -6107,4 +6107,15 @@ public class NumberFormatTest extends TestFmwk { Number number = fmt.parse("300,000"); assertEquals("Should use custom symbols and not monetary symbols", 300000L, number); } + + @Test + public void test11897_LocalizedPatternSeparator() { + DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(ULocale.ENGLISH); + dfs.setPatternSeparator('!'); + DecimalFormat df = new DecimalFormat("0", dfs); + df.applyPattern("a0;b0"); // should not throw + assertEquals("should apply the normal pattern", df.getNegativePrefix(), "b"); + df.applyLocalizedPattern("c0!d0"); // should not throw + assertEquals("should apply the localized pattern", df.getNegativePrefix(), "d"); + } } -- 2.40.0