summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Fischer <maxfischer2781@gmail.com>2021-06-21 20:07:40 +0200
committerMax Fischer <maxfischer2781@gmail.com>2021-06-21 20:07:40 +0200
commit831951b36faabed04c1b1d83af5d4d74692581a2 (patch)
tree03f817af0d38cb0617f0856481b57048b6e7ab67
parent960566b92a0c95d12fec3b293f8b0bf7ccb417bb (diff)
downloadpyparsing-git-831951b36faabed04c1b1d83af5d4d74692581a2.tar.gz
added tests for repetition rules
-rw-r--r--tests/test_unit.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py
index a8db17b..40fc1f0 100644
--- a/tests/test_unit.py
+++ b/tests/test_unit.py
@@ -8080,6 +8080,33 @@ class TestLR1_Recursion(ppt.TestParseResultsAsserts, TestCase):
def tearDown(self):
default_suite_context.restore()
+ def test_repeat_as_recurse(self):
+ """repetition rules formulated with recursion"""
+ one_or_more = pp.Forward("one_or_more")
+ one_or_more <<= one_or_more + "a" | "a"
+ self.assertParseResultsEquals(
+ one_or_more.parseString("a"),
+ expected_list=["a"],
+ )
+ self.assertParseResultsEquals(
+ one_or_more.parseString("aaa aa"),
+ expected_list=["a", "a", "a", "a", "a"],
+ )
+ delimited_list = pp.Forward("delimited_list")
+ delimited_list <<= delimited_list + pp.Suppress(',') + "b" | "b"
+ self.assertParseResultsEquals(
+ delimited_list.parseString("b"),
+ expected_list=["b"],
+ )
+ self.assertParseResultsEquals(
+ delimited_list.parseString("b,b"),
+ expected_list=["b", "b"],
+ )
+ self.assertParseResultsEquals(
+ delimited_list.parseString("b,b , b, b,b"),
+ expected_list=["b", "b", "b", "b", "b"],
+ )
+
def test_binary_recursive(self):
"""parsing of single left-recursive binary operator"""
expr = pp.Forward("expr")