From: Alex Morega Date: Sat, 6 Jul 2013 13:03:29 +0000 (+0200) Subject: test for range pluralization X-Git-Tag: 1.0~93^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30afd11e4effccd3d517bedc62f8cfdad4623ae2;p=thirdparty%2Fbabel.git test for range pluralization https://gist.github.com/mitsuhiko/5939731 --- diff --git a/tests/test_plural.py b/tests/test_plural.py index 644a97df..89a782bd 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) == "" + 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'