summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorbenselme <benselme@gmail.com>2015-01-08 17:07:11 -0500
committerbenselme <benselme@gmail.com>2015-01-08 17:07:11 -0500
commitdd64686bdabddd155d77146e7af25d6a88f2d189 (patch)
tree7c4b1190e69c3db12ed434581a51bb2a08b0025c /tests
parentb892e1941848db601fb699692a34736774bf5b63 (diff)
downloadbabel-dd64686bdabddd155d77146e7af25d6a88f2d189.tar.gz
Extract plural rule tokenization function and add tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_plural.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_plural.py b/tests/test_plural.py
index 7f31fd9..ad6da70 100644
--- a/tests/test_plural.py
+++ b/tests/test_plural.py
@@ -13,6 +13,7 @@
import doctest
import unittest
+import pytest
from babel import plural
@@ -98,3 +99,30 @@ def test_locales_with_no_plural_rules_have_default():
assert aa_plural(1) == 'other'
assert aa_plural(2) == 'other'
assert aa_plural(15) == 'other'
+
+
+WELL_FORMED_TOKEN_TESTS = (
+ ('', []),
+ ('n = 1', [('value', '1'), ('symbol', '='), ('word', 'n'), ]),
+ ('n = 1 @integer 1', [('value', '1'), ('symbol', '='), ('word', 'n'), ]),
+ ('n is 1', [('value', '1'), ('word', 'is'), ('word', 'n'), ]),
+ ('n % 100 = 3..10', [('value', '10'), ('ellipsis', '..'), ('value', '3'),
+ ('symbol', '='), ('value', '100'), ('symbol', '%'),
+ ('word', 'n'), ]),
+)
+
+
+@pytest.mark.parametrize('rule_text,tokens', WELL_FORMED_TOKEN_TESTS)
+def test_tokenize_well_formed(rule_text, tokens):
+ assert plural.tokenize_rule(rule_text) == tokens
+
+
+MALFORMED_TOKEN_TESTS = (
+ ('a = 1'), ('n ! 2'),
+)
+
+
+@pytest.mark.parametrize('rule_text', MALFORMED_TOKEN_TESTS)
+def test_tokenize_malformed(rule_text):
+ with pytest.raises(plural.RuleError):
+ plural.tokenize_rule(rule_text)