summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonah Lawrence <jonah@freshidea.com>2022-11-04 09:16:24 -0600
committerGitHub <noreply@github.com>2022-11-04 17:16:24 +0200
commit5fcc2535f96bfce9c1a1ecf9d19a976b9bf6ab6b (patch)
treea7871ea693786fe78eb10c5ff92e30926a71bfbb /tests
parent3add2c141783b1f590c753f475b8cba64d15cd0c (diff)
downloadbabel-5fcc2535f96bfce9c1a1ecf9d19a976b9bf6ab6b.tar.gz
feat: Support for short compact currency formats (#926)
Co-authored-by: Jun Omae (大前 潤) <42682+jun66j5@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_numbers.py29
-rw-r--r--tests/test_support.py5
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_numbers.py b/tests/test_numbers.py
index 1b955c9..bb6c4e8 100644
--- a/tests/test_numbers.py
+++ b/tests/test_numbers.py
@@ -422,6 +422,27 @@ def test_format_currency_format_type():
== u'1.099,98')
+def test_format_compact_currency():
+ assert numbers.format_compact_currency(1, 'USD', locale='en_US', format_type="short") == u'$1'
+ assert numbers.format_compact_currency(999, 'USD', locale='en_US', format_type="short") == u'$999'
+ assert numbers.format_compact_currency(123456789, 'USD', locale='en_US', format_type="short") == u'$123M'
+ assert numbers.format_compact_currency(123456789, 'USD', locale='en_US', fraction_digits=2, format_type="short") == u'$123.46M'
+ assert numbers.format_compact_currency(-123456789, 'USD', locale='en_US', fraction_digits=2, format_type="short") == u'-$123.46M'
+ assert numbers.format_compact_currency(1, 'JPY', locale='ja_JP', format_type="short") == u'¥1'
+ assert numbers.format_compact_currency(1234, 'JPY', locale='ja_JP', format_type="short") == u'¥1234'
+ assert numbers.format_compact_currency(123456, 'JPY', locale='ja_JP', format_type="short") == u'¥12万'
+ assert numbers.format_compact_currency(123456, 'JPY', locale='ja_JP', format_type="short", fraction_digits=2) == u'¥12.35万'
+ assert numbers.format_compact_currency(123, 'EUR', locale='yav', format_type="short") == '123\xa0€'
+ assert numbers.format_compact_currency(12345, 'EUR', locale='yav', format_type="short") == '12K\xa0€'
+ assert numbers.format_compact_currency(123456789, 'EUR', locale='de_DE', fraction_digits=1) == '123,5\xa0Mio.\xa0€'
+
+
+def test_format_compact_currency_invalid_format_type():
+ with pytest.raises(numbers.UnknownCurrencyFormatError):
+ numbers.format_compact_currency(1099.98, 'USD', locale='en_US',
+ format_type='unknown')
+
+
@pytest.mark.parametrize('input_value, expected_value', [
('10000', '$10,000.00'),
('1', '$1.00'),
@@ -696,3 +717,11 @@ def test_parse_decimal_nbsp_heuristics():
def test_very_small_decimal_no_quantization():
assert numbers.format_decimal(decimal.Decimal('1E-7'), locale='en', decimal_quantization=False) == '0.0000001'
+
+
+def test_single_quotes_in_pattern():
+ assert numbers.format_decimal(123, "'@0.#'00'@01'", locale='en') == '@0.#120@01'
+
+ assert numbers.format_decimal(123, "'$'''0", locale='en') == "$'123"
+
+ assert numbers.format_decimal(12, "'#'0 o''clock", locale='en') == "#12 o'clock"
diff --git a/tests/test_support.py b/tests/test_support.py
index 93ad37e..9447107 100644
--- a/tests/test_support.py
+++ b/tests/test_support.py
@@ -334,6 +334,11 @@ def test_format_compact_decimal():
assert fmt.compact_decimal(1234567, format_type='long', fraction_digits=2) == '1.23 million'
+def test_format_compact_currency():
+ fmt = support.Format('en_US')
+ assert fmt.compact_currency(1234567, "USD", format_type='short', fraction_digits=2) == '$1.23M'
+
+
def test_format_percent():
fmt = support.Format('en_US')
assert fmt.percent(0.34) == '34%'