diff options
author | ptmcg <ptmcg@austin.rr.com> | 2021-09-24 08:44:30 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2021-09-24 08:44:30 -0500 |
commit | 9adaf2e261f4b10b60f16bd553fcae88e541c471 (patch) | |
tree | 10fb72c587fa686a06331c2fe1e258329dac24a0 /tests | |
parent | 8d1083f7db349d00c25993a7bd4dab415af0582e (diff) | |
download | pyparsing-git-9adaf2e261f4b10b60f16bd553fcae88e541c471.tar.gz |
Allow multiplying an expr by 0 or (0,0)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_unit.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py index 6df6002..1ad8f82 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -2477,12 +2477,6 @@ class Test02_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase): def testParserElementMulOperatorWithTuples(self): """test ParserElement "*" with various tuples""" - # ParserElement * (0, 0) - with self.assertRaises( - ValueError, msg="ParserElement * (0,0) should raise error" - ): - expr = pp.Word(pp.alphas)("first") + pp.Word(pp.nums)("second*") * (0, 0) - # ParserElement * (None, n) expr = pp.Word(pp.alphas)("first") + pp.Word(pp.nums)("second*") * (None, 3) @@ -2556,6 +2550,18 @@ class Test02_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase): ): expr = pp.Word(pp.alphas)("first") + pp.Word(pp.nums)("second") * ("2", "3") + def testParserElementMulByZero(self): + alpwd = pp.Word(pp.alphas) + numwd = pp.Word(pp.nums) + + test_string = "abd def ghi jkl" + + parser = alpwd * 2 + numwd * 0 + alpwd * 2 + self.assertParseAndCheckList(parser, test_string, expected_list=test_string.split()) + + parser = alpwd * 2 + numwd * (0, 0) + alpwd * 2 + self.assertParseAndCheckList(parser, test_string, expected_list=test_string.split()) + def testParserElementMulOperatorWithOtherTypes(self): """test the overridden "*" operator with other data types""" |