summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMax Fischer <maxfischer2781@gmail.com>2021-06-20 15:37:00 +0200
committerMax Fischer <maxfischer2781@gmail.com>2021-06-20 15:37:00 +0200
commit9b586b9903571c381fca06514cde243e8655c680 (patch)
tree4de1a502a6fd70df11116d139c1a4f4c73a1a813 /tests
parentbdf5fd15339b97bb7fc5084ab6605760b06e3b60 (diff)
downloadpyparsing-git-9b586b9903571c381fca06514cde243e8655c680.tar.gz
unittest for empty and non-peg clauses
Diffstat (limited to 'tests')
-rw-r--r--tests/test_unit.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py
index ad16154..0ebb8cc 100644
--- a/tests/test_unit.py
+++ b/tests/test_unit.py
@@ -8169,6 +8169,21 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
self.assertEqual(expr.parseString("1*2^3")[0], 1*2**3)
self.assertEqual(expr.parseString("4^3^2^1")[0], 4**3**2**1)
+ def test_terminate_empty(self):
+ """Recursion with ``Empty`` terminates"""
+ empty = pp.Forward('e')
+ empty <<= empty + pp.Empty() | pp.Empty()
+ self.assertParseResultsEquals(empty.parseString(""), expected_list=[])
+
+ def test_non_peg(self):
+ """Recursion works for non-PEG operators"""
+ expr = pp.Forward('expr')
+ expr <<= expr + "a" ^ e + "ab" ^ e + "abc"
+ self.assertParseResultsEquals(
+ e.parseString("abcabaabc"),
+ expected_list=["abc", "ab", "a", "abc"]
+ )
+
# force clear of packrat parsing flags before saving contexts
pp.ParserElement._packratEnabled = False