summaryrefslogtreecommitdiff
path: root/tests/test_plural.py
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2015-12-20 23:28:00 +0200
committerAarni Koskela <akx@iki.fi>2016-01-22 20:43:20 +0200
commite31156fa2012b637923b2f047b8f24fd3c0e8423 (patch)
tree7cb1f926bd3892e9af25694328e2a1ed88af04a1 /tests/test_plural.py
parenta4ed4e04d02bdeeec3d97118215876dcce52852a (diff)
downloadbabel-e31156fa2012b637923b2f047b8f24fd3c0e8423.tar.gz
Compile noninteger TR35 operands to zeroes when emitting Gettext
See http://www.unicode.org/reports/tr35/tr35-numbers.html#Operands See https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html Fixes #287
Diffstat (limited to 'tests/test_plural.py')
-rw-r--r--tests/test_plural.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/test_plural.py b/tests/test_plural.py
index fce1b8e..d51efef 100644
--- a/tests/test_plural.py
+++ b/tests/test_plural.py
@@ -13,7 +13,7 @@
import unittest
import pytest
-from babel import plural
+from babel import plural, localedata
from babel._compat import Decimal
@@ -254,3 +254,17 @@ def test_extract_operands(source, n, i, v, w, f, t):
source = Decimal(source) if isinstance(source, str) else source
assert (plural.extract_operands(source) ==
Decimal(n), i, v, w, f, t)
+
+
+@pytest.mark.parametrize('locale', ('ru', 'pl'))
+def test_gettext_compilation(locale):
+ # Test that new plural form elements introduced in recent CLDR versions
+ # are compiled "down" to `n` when emitting Gettext rules.
+ ru_rules = localedata.load(locale)['plural_form'].rules
+ chars = 'ivwft'
+ # Test that these rules are valid for this test; i.e. that they contain at least one
+ # of the gettext-unsupported characters.
+ assert any((" " + ch + " ") in rule for ch in chars for rule in ru_rules.values())
+ # Then test that the generated value indeed does not contain these.
+ ru_rules_gettext = plural.to_gettext(ru_rules)
+ assert not any(ch in ru_rules_gettext for ch in chars)