1 #! /usr/bin/env python3
4 from lark import LexError, ParseError
5 from parser import parse
8 class TestParser(unittest.TestCase):
9 def _parse(self, input):
12 def test_02_tag(self):
13 self.assertEqual(self._parse('xxx'), ('NAME', 'xxx'))
15 def test_03_bad_tag(self):
16 self.assertRaises(LexError, self._parse, 'XXX')
18 def test_04_expression(self):
20 self._parse('!(xxx&yyy)'),
21 ('NOT', ('PARENS', ('AND', ('NAME', 'xxx'), ('NAME', 'yyy'))))
24 self._parse('!(xxx & yyy)'),
25 ('NOT', ('PARENS', ('AND', ('NAME', 'xxx'), ('NAME', 'yyy'))))
28 self._parse('!xxx&yyy&zzz|ooo'),
30 ('NOT', ('NAME', 'xxx')),
31 ('AND', ('NAME', 'yyy'), ('NAME', 'zzz'))),
35 self._parse('!(xxx && yyy)'),
36 ('NOT', ('PARENS', ('AND', ('NAME', 'xxx'), ('NAME', 'yyy'))))
39 self._parse('!(xxx || yyy)'),
40 ('NOT', ('PARENS', ('OR', ('NAME', 'xxx'), ('NAME', 'yyy'))))
43 self._parse('xxx and yyy'),
44 ('AND', ('NAME', 'xxx'), ('NAME', 'yyy'))
47 self._parse('xxx or yyy'),
48 ('OR', ('NAME', 'xxx'), ('NAME', 'yyy'))
51 self._parse('xxx OR yyy'),
52 ('OR', ('NAME', 'xxx'), ('NAME', 'yyy'))
55 self._parse('not xxx'),
56 ('NOT', ('NAME', 'xxx'))
59 self._parse('NOT xxx'),
60 ('NOT', ('NAME', 'xxx'))
63 self._parse('NOT (xxx & yyy) AND zzz | ooo'),
68 ('AND', ('NAME', 'xxx'), ('NAME', 'yyy'))
77 def test_05_bad_expression(self):
78 self.assertRaises(ParseError, self._parse, '!(xxx&yyy')
81 if __name__ == "__main__":