diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 2dbc30ddae..2c504b26cd 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 3239619bfc..3f97bc682c 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 3cd2cc6dba..796d116de7 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"); + } }