summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2020-10-11 14:21:09 -0500
committerptmcg <ptmcg@austin.rr.com>2020-10-11 14:21:09 -0500
commit5713fba4fc952cd08a136301ff84275f19e1e930 (patch)
tree267deccbc8711e68bd25e0957021dbc35142c3a4 /tests
parent1add43913c92157add7823e58e961a20fcf5c31c (diff)
downloadpyparsing-git-5713fba4fc952cd08a136301ff84275f19e1e930.tar.gz
Fixed bugs in Each with ZeroOrMore and OneOrMore (first matched element enclosed in extra nesting level; results names not maintained; did not handle mix with required expressions)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_unit.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py
index 11b86a6..1d6e28b 100644
--- a/tests/test_unit.py
+++ b/tests/test_unit.py
@@ -4636,6 +4636,41 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
"incorrect exception raised for test string {!r}".format(test_str),
)
+ def testEachWithMultipleMatch(self):
+ size = "size" + pp.oneOf("S M L XL")
+ color = pp.Group(
+ "color" + pp.oneOf("red orange yellow green blue purple white black brown")
+ )
+ size.setName("size_spec")
+ color.setName("color_spec")
+
+ spec0 = size("size") & color[...]("colors")
+ spec1 = size("size") & color[1, ...]("colors")
+
+ for spec in (spec0, spec1):
+ for test, expected_dict in [
+ (
+ "size M color red color yellow",
+ {
+ "colors": [["color", "red"], ["color", "yellow"]],
+ "size": ["size", "M"],
+ },
+ ),
+ (
+ "color green size M color red color yellow",
+ {
+ "colors": [
+ ["color", "green"],
+ ["color", "red"],
+ ["color", "yellow"],
+ ],
+ "size": ["size", "M"],
+ },
+ ),
+ ]:
+ result = spec.parseString(test, parseAll=True)
+ self.assertParseResultsEquals(result, expected_dict=expected_dict)
+
def testSumParseResults(self):
samplestr1 = "garbage;DOB 10-10-2010;more garbage\nID PARI12345678;more garbage"