TESTCASE_AUTO(Test13734_StrictFlexibleWhitespace);
TESTCASE_AUTO(Test20961_CurrencyPluralPattern);
TESTCASE_AUTO(Test21134_ToNumberFormatter);
+ TESTCASE_AUTO(Test13733_StrictAndLenient);
TESTCASE_AUTO_END;
}
result3.toTempString(status));
}
+void NumberFormatTest::Test13733_StrictAndLenient() {
+ IcuTestErrorCode status(*this, "Test13733_StrictAndLenient");
+
+ static const struct TestCase {
+ const char16_t* inputString;
+ const char16_t* patternString;
+ int64_t expectedStrictParse;
+ int64_t expectedLenientParse;
+ } cases[] = { {u"CA$ 12", u"¤ 0", 12, 12},
+ {u"CA$12", u"¤0", 12, 12},
+ {u"CAD 12", u"¤¤ 0", 12, 12},
+ {u"12 CAD", u"0 ¤¤", 12, 12},
+ {u"12 Canadian dollars", u"0 ¤¤¤", 12, 12},
+ {u"$12 ", u"¤¤¤¤0", 12, 12},
+ {u"12$", u"0¤¤¤¤", 12, 12},
+ {u"CA$ 12", u"¤0", 0, 12},
+ {u"CA$ 12", u"0 ¤¤", 0, 12},
+ {u"CA$ 12", u"0 ¤¤¤", 0, 12},
+ {u"CA$ 12", u"¤¤¤¤0", 0, 12},
+ {u"CA$ 12", u"0¤¤¤¤", 0, 12},
+ {u"CA$12", u"¤ 0", 0, 12},
+ {u"CA$12", u"¤¤ 0", 0, 12},
+ {u"CA$12", u"0 ¤¤", 0, 12},
+ {u"CA$12", u"0 ¤¤¤", 0, 12},
+ {u"CA$12", u"0¤¤¤¤", 0, 12},
+ {u"CAD 12", u"¤0", 0, 12},
+ {u"CAD 12", u"0 ¤¤", 0, 12},
+ {u"CAD 12", u"0 ¤¤¤", 0, 12},
+ {u"CAD 12", u"¤¤¤¤0", 0, 12},
+ {u"CAD 12", u"0¤¤¤¤", 0, 12},
+ {u"12 CAD", u"¤ 0", 0, 12},
+ {u"12 CAD", u"¤0", 0, 12},
+ {u"12 CAD", u"¤¤ 0", 0, 12},
+ {u"12 CAD", u"¤¤¤¤0", 0, 12},
+ {u"12 CAD", u"0¤¤¤¤", 0, 12},
+ {u"12 Canadian dollars", u"¤ 0", 0, 12},
+ {u"12 Canadian dollars", u"¤0", 0, 12},
+ {u"12 Canadian dollars", u"¤¤ 0", 0, 12},
+ {u"12 Canadian dollars", u"¤¤¤¤0", 0, 12},
+ {u"12 Canadian dollars", u"0¤¤¤¤", 0, 12},
+ {u"$12 ", u"¤ 0", 0, 12},
+ {u"$12 ", u"¤¤ 0", 0, 12},
+ {u"$12 ", u"0 ¤¤", 0, 12},
+ {u"$12 ", u"0 ¤¤¤", 0, 12},
+ {u"$12 ", u"0¤¤¤¤", 0, 12},
+ {u"12$", u"¤ 0", 0, 12},
+ {u"12$", u"¤0", 0, 12},
+ {u"12$", u"¤¤ 0", 0, 12},
+ {u"12$", u"0 ¤¤", 0, 12},
+ {u"12$", u"0 ¤¤¤", 0, 12},
+ {u"12$", u"¤¤¤¤0", 0, 12} };
+ for (auto& cas : cases) {
+ UnicodeString inputString(cas.inputString);
+ UnicodeString patternString(cas.patternString);
+ int64_t parsedStrictValue = 0;
+ int64_t parsedLenientValue = 0;
+ ParsePosition ppos;
+
+ DecimalFormatSymbols dfs(Locale::getEnglish(), status);
+ DecimalFormat df(patternString, dfs, status);
+ df.setLenient(FALSE);
+ LocalPointer<CurrencyAmount> ca_strict(df.parseCurrency(inputString, ppos));
+ if (ca_strict != nullptr) {
+ parsedStrictValue = ca_strict->getNumber().getInt64();
+ }
+ assertEquals("Strict parse of " + inputString + " using " + patternString,
+ parsedStrictValue, cas.expectedStrictParse);
+
+ ppos.setIndex(0);
+ df.setLenient(TRUE);
+ LocalPointer<CurrencyAmount> ca_lenient(df.parseCurrency(inputString, ppos));
+ Formattable parsedNumber_lenient = ca_lenient->getNumber();
+ if (ca_lenient != nullptr) {
+ parsedLenientValue = ca_lenient->getNumber().getInt64();
+ }
+ assertEquals("Lenient parse of " + inputString + " using " + patternString,
+ parsedLenientValue, cas.expectedLenientParse);
+ }
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */
DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance(ULocale.US, NumberFormat.PLURALCURRENCYSTYLE);
assertEquals("Currency pattern", "#,##0.00 ¤¤¤", decimalFormat.toPattern());
}
+
+ @Test
+ public void test13733_StrictAndLenient() {
+ Object[][] cases = { {"CA$ 12", "¤ 0", 12, 12},
+ {"CA$12", "¤0", 12, 12},
+ {"CAD 12", "¤¤ 0", 12, 12},
+ {"12 CAD", "0 ¤¤", 12, 12},
+ {"12 Canadian dollars", "0 ¤¤¤", 12, 12},
+ {"$12 ", "¤¤¤¤0", 12, 12},
+ {"12$", "0¤¤¤¤", 12, 12},
+ {"CA$ 12", "¤0", 0, 12},
+ {"CA$ 12", "0 ¤¤", 0, 12},
+ {"CA$ 12", "0 ¤¤¤", 0, 12},
+ {"CA$ 12", "¤¤¤¤0", 0, 12},
+ {"CA$ 12", "0¤¤¤¤", 0, 12},
+ {"CA$12", "¤ 0", 0, 12},
+ {"CA$12", "¤¤ 0", 0, 12},
+ {"CA$12", "0 ¤¤", 0, 12},
+ {"CA$12", "0 ¤¤¤", 0, 12},
+ {"CA$12", "0¤¤¤¤", 0, 12},
+ {"CAD 12", "¤0", 0, 12},
+ {"CAD 12", "0 ¤¤", 0, 12},
+ {"CAD 12", "0 ¤¤¤", 0, 12},
+ {"CAD 12", "¤¤¤¤0", 0, 12},
+ {"CAD 12", "0¤¤¤¤", 0, 12},
+ {"12 CAD", "¤ 0", 0, 12},
+ {"12 CAD", "¤0", 0, 12},
+ {"12 CAD", "¤¤ 0", 0, 12},
+ {"12 CAD", "¤¤¤¤0", 0, 12},
+ {"12 CAD", "0¤¤¤¤", 0, 12},
+ {"12 Canadian dollars", "¤ 0", 0, 12},
+ {"12 Canadian dollars", "¤0", 0, 12},
+ {"12 Canadian dollars", "¤¤ 0", 0, 12},
+ {"12 Canadian dollars", "¤¤¤¤0", 0, 12},
+ {"12 Canadian dollars", "0¤¤¤¤", 0, 12},
+ {"$12 ", "¤ 0", 0, 12},
+ {"$12 ", "¤¤ 0", 0, 12},
+ {"$12 ", "0 ¤¤", 0, 12},
+ {"$12 ", "0 ¤¤¤", 0, 12},
+ {"$12 ", "0¤¤¤¤", 0, 12},
+ {"12$", "¤ 0", 0, 12},
+ {"12$", "¤0", 0, 12},
+ {"12$", "¤¤ 0", 0, 12},
+ {"12$", "0 ¤¤", 0, 12},
+ {"12$", "0 ¤¤¤", 0, 12},
+ {"12$", "¤¤¤¤0", 0, 12} };
+
+ for (Object[] cas : cases) {
+ String inputString = (String) cas[0];
+ String patternString = (String) cas[1];
+ int expectedStrictParse = (int) cas[2];
+ int expectedLenientParse = (int) cas[3];
+
+ int parsedStrictValue = 0;
+ int parsedLenientValue = 0;
+ ParsePosition ppos = new ParsePosition(0);
+ DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(ULocale.ENGLISH);
+ DecimalFormat df = new DecimalFormat(patternString, dfs);
+
+ df.setParseStrict(true);
+ CurrencyAmount ca_strict = df.parseCurrency(inputString, ppos);
+ if (null != ca_strict) {
+ parsedStrictValue = ca_strict.getNumber().intValue();
+ }
+ assertEquals("Strict parse of " + inputString + " using " + patternString,
+ parsedStrictValue, expectedStrictParse);
+
+ ppos.setIndex(0);
+ df.setParseStrict(false);
+ CurrencyAmount ca_lenient = df.parseCurrency(inputString, ppos);
+ if (null != ca_lenient) {
+ parsedLenientValue = ca_lenient.getNumber().intValue();
+ }
+ assertEquals("Strict parse of " + inputString + " using " + patternString,
+ parsedLenientValue, expectedLenientParse);
+ }
+ }
}