summaryrefslogtreecommitdiff
path: root/tests/test_plural.py
diff options
context:
space:
mode:
authorAlex Morega <alex@grep.ro>2013-07-06 15:03:29 +0200
committerAlex Morega <alex@grep.ro>2013-07-06 15:03:46 +0200
commit30afd11e4effccd3d517bedc62f8cfdad4623ae2 (patch)
treefa0a003b5ad0814582f4f2cf9f56d1036d5ab997 /tests/test_plural.py
parentcf115e60736c46437cdd58ba347d508eca854a89 (diff)
downloadbabel-30afd11e4effccd3d517bedc62f8cfdad4623ae2.tar.gz
test for range pluralization
https://gist.github.com/mitsuhiko/5939731
Diffstat (limited to 'tests/test_plural.py')
-rw-r--r--tests/test_plural.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_plural.py b/tests/test_plural.py
index 644a97d..89a782b 100644
--- a/tests/test_plural.py
+++ b/tests/test_plural.py
@@ -68,3 +68,25 @@ def test_cldr_modulo():
assert plural.cldr_modulo(-3, 5) == -3
assert plural.cldr_modulo(-3, -5) == -3
assert plural.cldr_modulo(3, 5) == 3
+
+
+def test_plural_within_rules():
+ p = plural.PluralRule({'one': 'n is 1', 'few': 'n within 2,4,7..9'})
+ assert repr(p) == "<PluralRule 'one: n is 1, few: n within 2,4,7..9'>"
+ assert plural.to_javascript(p) == (
+ "(function(n) { "
+ "return ((n == 2) || (n == 4) || (n >= 7 && n <= 9))"
+ " ? 'few' : (n == 1) ? 'one' : 'other'; })")
+ assert plural.to_gettext(p) == (
+ 'nplurals=3; plural=(((n == 2) || (n == 4) || (n >= 7 && n <= 9))'
+ ' ? 1 : (n == 1) ? 0 : 2)')
+ assert p(0) == 'other'
+ assert p(1) == 'one'
+ assert p(2) == 'few'
+ assert p(3) == 'other'
+ assert p(4) == 'few'
+ assert p(5) == 'other'
+ assert p(6) == 'other'
+ assert p(7) == 'few'
+ assert p(8) == 'few'
+ assert p(9) == 'few'