]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
test for range pluralization
authorAlex Morega <alex@grep.ro>
Sat, 6 Jul 2013 13:03:29 +0000 (15:03 +0200)
committerAlex Morega <alex@grep.ro>
Sat, 6 Jul 2013 13:03:46 +0000 (15:03 +0200)
https://gist.github.com/mitsuhiko/5939731

tests/test_plural.py

index 644a97dfb37a809e6ab09f2b89c97dda275709c8..89a782bd015d8f18d942e7c223bba1f5449e2ba2 100644 (file)
@@ -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'