ICU-11897 Adding tests for localized pattern separator symbol.

X-SVN-Rev: 41292
This commit is contained in:
Shane Carr 2018-04-28 07:27:02 +00:00
parent b20f7f3543
commit 28e9f69378
3 changed files with 26 additions and 0 deletions

View 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 */

View 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);

View 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");
}
}