Fix compactCurrency to correctly use passed-in symbol
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132708973
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e528f4..3de399c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+## 0.15.0
+ * Fix compactCurrency to correctly use passed-in symbol.
+
## 0.14.0
* MAJOR BREAKING CHANGE! Remove message extraction and code generation into a
separate intl_translation package. This means packages with a runtime
diff --git a/lib/src/intl/number_format.dart b/lib/src/intl/number_format.dart
index 6f16d6d..d1410ab 100644
--- a/lib/src/intl/number_format.dart
+++ b/lib/src/intl/number_format.dart
@@ -536,6 +536,8 @@
locale: locale,
formatType: _CompactFormatType.COMPACT_DECIMAL_SHORT_CURRENCY_PATTERN,
name: name,
+ getPattern: (symbols) => symbols.CURRENCY_PATTERN,
+ currencySymbol: symbol,
decimalDigits: decimalDigits,
isForCurrency: true);
}
diff --git a/test/number_format_compact_test.dart b/test/number_format_compact_test.dart
index 53cd593..4648a20 100644
--- a/test/number_format_compact_test.dart
+++ b/test/number_format_compact_test.dart
@@ -64,11 +64,17 @@
testCurrency("it", 4420, "4420\u00A0\$", "4000\u00A0\$", currency: 'CAD');
testCurrency("it", 4420000, "4,42\u00A0Mio\u00A0\$", "4\u00A0Mio\u00A0\$",
currency: 'USD');
+
+ test("Explicit non-default symbol with compactCurrency", () {
+ var format = new NumberFormat.compactCurrency(locale: "ja", symbol: "()");
+ var result = format.format(98765);
+ expect(result, "()9.88\u4e07");
+ });
}
testCurrency(String locale, num number, String expected, String expectedShort,
{String currency}) {
- test("Compact currency for $locale, $number", () {
+ test("Compact simple currency for $locale, $number", () {
var format =
new NumberFormat.compactSimpleCurrency(locale: locale, name: currency);
var result = format.format(number);
@@ -79,6 +85,26 @@
var shortResult = shortFormat.format(number);
expect(shortResult, expectedShort);
});
+ test("Compact currency for $locale, $number", () {
+ var symbols = {
+ "ja": "¥",
+ "en_US": r"$",
+ "ru": "руб.",
+ "it": "€",
+ "CAD": r"$",
+ "USD": r"$"
+ };
+ var symbol = symbols[currency] ?? symbols[locale];
+ var format = new NumberFormat.compactCurrency(
+ locale: locale, name: currency, symbol: symbol);
+ var result = format.format(number);
+ expect(result, expected);
+ var shortFormat = new NumberFormat.compactCurrency(
+ locale: locale, name: currency, symbol: symbol);
+ shortFormat.significantDigits = 1;
+ var shortResult = shortFormat.format(number);
+ expect(shortResult, expectedShort);
+ });
}
// TODO(alanknight): Don't just skip the whole locale if there's one problem