From 230aad94a7c5df9b4a1bc4ef05dd873bd236f12e Mon Sep 17 00:00:00 2001 From: julienmalard Date: Tue, 30 Jun 2020 08:07:31 -0400 Subject: [PATCH] Added reconstructor tests for tokens to keep ("!") and for expanded rules. --- tests/test_reconstructor.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_reconstructor.py b/tests/test_reconstructor.py index ecab499..7a896a0 100644 --- a/tests/test_reconstructor.py +++ b/tests/test_reconstructor.py @@ -69,6 +69,36 @@ class TestReconstructor(TestCase): self.assert_reconstruct(g, code) + def test_keep_tokens(self): + g = """ + start: (NL | stmt)* + stmt: var op var + !op: ("+" | "-" | "*" | "/") + var: WORD + NL: /(\\r?\\n)+\s*/ + """ + common + + code = """ + a+b + """ + + self.assert_reconstruct(g, code) + + @unittest.skip('Not working yet') + def test_expand_rule(self): + g = """ + ?start: (NL | mult_stmt)* + ?mult_stmt: sum_stmt ["*" sum_stmt] + ?sum_stmt: var ["+" var] + var: WORD + NL: /(\\r?\\n)+\s*/ + """ + common + + code = ['a', 'a*b', 'a+b', 'a*b+c', 'a+b*c', 'a+b*c+d'] + + for c in code: + self.assert_reconstruct(g, c) + def test_json_example(self): test_json = ''' {