summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorbenselme <benselme@gmail.com>2015-01-09 15:35:21 -0500
committerbenselme <benselme@gmail.com>2015-01-09 15:35:21 -0500
commit98fa4b6ca174e1ef3b0fbd9557b2006d38a52f60 (patch)
tree95248318baa43c7e4196d98b9c153e6cfde71338 /tests
parent9327e0824a1bbed538e73d42b971988f8214b490 (diff)
downloadbabel-98fa4b6ca174e1ef3b0fbd9557b2006d38a52f60.tar.gz
Make sure extract_operands is always called when using plural.to_python, add tests to check operands eval works
Diffstat (limited to 'tests')
-rw-r--r--tests/test_plural.py41
1 files changed, 37 insertions, 4 deletions
diff --git a/tests/test_plural.py b/tests/test_plural.py
index ece1358..278b5db 100644
--- a/tests/test_plural.py
+++ b/tests/test_plural.py
@@ -11,11 +11,8 @@
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://babel.edgewall.org/log/.
import decimal
-
-import doctest
import unittest
import pytest
-from decimal import Decimal as Dec
from babel import plural
@@ -28,6 +25,40 @@ def test_plural_rule():
assert rule.rules == {'one': 'n is 1'}
+def test_plural_rule_operands_i():
+ rule = plural.PluralRule({'one': 'i is 1'})
+ assert rule(1.2) == 'one'
+ assert rule(2) == 'other'
+
+
+def test_plural_rule_operands_v():
+ rule = plural.PluralRule({'one': 'v is 2'})
+ assert rule(decimal.Decimal('1.20')) == 'one'
+ assert rule(decimal.Decimal('1.2')) == 'other'
+ assert rule(2) == 'other'
+
+
+def test_plural_rule_operands_w():
+ rule = plural.PluralRule({'one': 'w is 2'})
+ assert rule(decimal.Decimal('1.23')) == 'one'
+ assert rule(decimal.Decimal('1.20')) == 'other'
+ assert rule(1.2) == 'other'
+
+
+def test_plural_rule_operands_f():
+ rule = plural.PluralRule({'one': 'f is 20'})
+ assert rule(decimal.Decimal('1.23')) == 'other'
+ assert rule(decimal.Decimal('1.20')) == 'one'
+ assert rule(1.2) == 'other'
+
+
+def test_plural_rule_operands_t():
+ rule = plural.PluralRule({'one': 't = 5'})
+ assert rule(decimal.Decimal('1.53')) == 'other'
+ assert rule(decimal.Decimal('1.50')) == 'one'
+ assert rule(1.5) == 'one'
+
+
def test_plural_other_is_ignored():
rule = plural.PluralRule({'one': 'n is 1', 'other': '@integer 2'})
assert rule(1) == 'one'
@@ -213,10 +244,12 @@ EXTRACT_OPERANDS_TESTS = (
('1.03', '1.03', 1, 2, 2, 3, 3),
('1.230', '1.230', 1, 3, 2, 230, 23),
(-1, 1, 1, 0, 0, 0, 0),
+ (1.3, '1.3', 1, 1, 1, 3, 3),
)
@pytest.mark.parametrize('source,n,i,v,w,f,t', EXTRACT_OPERANDS_TESTS)
def test_extract_operands(source, n, i, v, w, f, t):
- assert (plural.extract_operands(decimal.Decimal(source)) ==
+ source = decimal.Decimal(source) if isinstance(source, str) else source
+ assert (plural.extract_operands(source) ==
decimal.Decimal(n), i, v, w, f, t)