]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
make sure rules are always sorted
authorAlex Morega <alex@grep.ro>
Sun, 7 Jul 2013 10:59:47 +0000 (12:59 +0200)
committerAlex Morega <alex@grep.ro>
Sun, 7 Jul 2013 11:02:27 +0000 (13:02 +0200)
babel/plural.py
tests/test_plural.py

index c3137dbf33f04804000a9d614f8fdb6523098e6f..afc6d1e1f33173f1ef9c4782ec57ee2ff6fc92b0 100644 (file)
@@ -57,7 +57,7 @@ class PluralRule(object):
             rules = rules.items()
         found = set()
         self.abstract = []
-        for key, expr in rules:
+        for key, expr in sorted(list(rules)):
             if key not in _plural_tags:
                 raise ValueError('unknown tag %r' % key)
             elif key in found:
@@ -180,7 +180,7 @@ def to_gettext(rule):
     technically limited to integers and returns indices rather than tags.
 
     >>> to_gettext({'one': 'n is 1', 'two': 'n is 2'})
-    'nplurals=3; plural=((n == 2) ? 1 : (n == 1) ? 0 : 2)'
+    'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2)'
 
     :param rule: the rules as list or dict, or a `PluralRule` object
     :return: an equivalent gettext-style plural expression
index 89a782bd015d8f18d942e7c223bba1f5449e2ba2..5fe67a54833ace9451b56ca3bc81ff86113391c0 100644 (file)
@@ -43,7 +43,7 @@ def test_to_python():
 
 def test_to_gettext():
     assert (plural.to_gettext({'one': 'n is 1', 'two': 'n is 2'})
-            == 'nplurals=3; plural=((n == 2) ? 1 : (n == 1) ? 0 : 2)')
+            == 'nplurals=3; plural=((n == 1) ? 0 : (n == 2) ? 1 : 2)')
 
 
 def test_in_range_list():