]> granicus.if.org Git - icu/commitdiff
ICU-11897 Adding tests for localized pattern separator symbol.
authorShane Carr <shane@unicode.org>
Sat, 28 Apr 2018 07:27:02 +0000 (07:27 +0000)
committerShane Carr <shane@unicode.org>
Sat, 28 Apr 2018 07:27:02 +0000 (07:27 +0000)
X-SVN-Rev: 41292

icu4c/source/test/intltest/numfmtst.cpp
icu4c/source/test/intltest/numfmtst.h
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java

index 2dbc30ddaed9e83b4bb7691351c06738c2225710..2c504b26cd6a8c3580ed48408186db114459a0bc 100644 (file)
@@ -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 */
index 3239619bfcc74efbd9c816d6e375cc7861c41b02..3f97bc682c2d563c0ac8a5b40693dc6c8263fdb1 100644 (file)
@@ -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);
index 3cd2cc6dba4a17e38f877211f3553b06e60963b5..796d116de7843c23a9dcd83c9161215771ca5ef2 100644 (file)
@@ -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");
+    }
 }