From e463ce92ff950917ad632c36c07b403d2410df98 Mon Sep 17 00:00:00 2001 From: benselme Date: Thu, 8 Jan 2015 19:22:20 -0500 Subject: [PATCH] More plural._Parser tests --- tests/test_plural.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/test_plural.py b/tests/test_plural.py index d20d186a..489c0efc 100644 --- a/tests/test_plural.py +++ b/tests/test_plural.py @@ -161,18 +161,40 @@ def make_range_list(*values): class PluralRuleParserTestCase(unittest.TestCase): def setUp(self): self.n = plural.ident_node('n') - self.n_eq_1 = ('relation', ('in', self.n, make_range_list(1))) + + def n_eq(self, v): + return 'relation', ('in', self.n, make_range_list(v)) def test_error_when_unexpected_end(self): with pytest.raises(plural.RuleError): plural._Parser('n =') def test_eq_relation(self): - assert plural._Parser('n = 1').ast == self.n_eq_1 + assert plural._Parser('n = 1').ast == self.n_eq(1) def test_in_range_relation(self): assert plural._Parser('n = 2..4').ast == \ ('relation', ('in', self.n, make_range_list((2, 4)))) def test_negate(self): - assert plural._Parser('n != 1').ast == plural.negate(self.n_eq_1) \ No newline at end of file + assert plural._Parser('n != 1').ast == plural.negate(self.n_eq(1)) + + def test_or(self): + assert plural._Parser('n = 1 or n = 2').ast ==\ + ('or', (self.n_eq(1), self.n_eq(2))) + + def test_and(self): + assert plural._Parser('n = 1 and n = 2').ast ==\ + ('and', (self.n_eq(1), self.n_eq(2))) + + def test_or_and(self): + assert plural._Parser('n = 0 or n != 1 and n % 100 = 1..19' ).ast ==\ + ('or', (self.n_eq(0), + ('and', (plural.negate(self.n_eq(1)), + ('relation', ('in', + ('mod', (self.n, + plural.value_node(100))), + (make_range_list((1, 19)))))) + ) + ) + ) \ No newline at end of file -- 2.47.2