summaryrefslogtreecommitdiff
path: root/unitTests.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2019-07-02 16:32:22 -0500
committerPaul McGuire <ptmcg@austin.rr.com>2019-07-02 16:32:22 -0500
commitf20f8c038bebb81e7184ac87a6f13d5d81d3b495 (patch)
tree8bb5dcb34b8b87d15df62ee7e85adc331878290c /unitTests.py
parentf5de46966a55b8c651f7ff92440665af02567df4 (diff)
downloadpyparsing-git-f20f8c038bebb81e7184ac87a6f13d5d81d3b495.tar.gz
Issue #93 - interaction of Or and addCondition sometimes selects alternative that is not the longest
Diffstat (limited to 'unitTests.py')
-rw-r--r--unitTests.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/unitTests.py b/unitTests.py
index f3be763..455c54b 100644
--- a/unitTests.py
+++ b/unitTests.py
@@ -2860,7 +2860,23 @@ class PatientOrTest(ParseTestCase):
failed = True
else:
failed = False
- self.assertFalse(failed, "invalid logic in Or, fails on longest match with exception in parse action")
+ self.assertFalse(failed, "invalid logic in Or, fails on longest match with exception in parse action")
+
+ # from issue #93
+ word = pp.Word(pp.alphas).setName('word')
+ word_1 = pp.Word(pp.alphas).setName('word_1').addCondition(lambda t: len(t[0]) == 1)
+
+ a = word + (word_1 + word ^ word)
+ b = word * 3
+ c = a ^ b
+ c.streamline()
+ print_(c)
+ test_string = 'foo bar temp'
+ result = c.parseString(test_string)
+ print_(test_string, '->', result.asList())
+
+ self.assertEqual(result.asList(), test_string.split(), "failed to match longest choice")
+
class EachWithOptionalWithResultsNameTest(ParseTestCase):
def runTest(self):