summaryrefslogtreecommitdiff
path: root/unitTests.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2019-03-30 02:24:36 -0500
committerPaul McGuire <ptmcg@austin.rr.com>2019-03-30 02:24:36 -0500
commit897696352f4b0a03152058c01403a42b07be650c (patch)
tree44c148bd14735d96ecd7ac6fe90bde919f45b8a2 /unitTests.py
parentae5adb02bf7e991111c05e71f9fb29c63b8cb11d (diff)
downloadpyparsing-git-897696352f4b0a03152058c01403a42b07be650c.tar.gz
Add __compat__.collect_all_And_tokens to address version incompatibility, and conditionalize API-breaking behavior (#69)
Diffstat (limited to 'unitTests.py')
-rw-r--r--unitTests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/unitTests.py b/unitTests.py
index 4786255..caf538d 100644
--- a/unitTests.py
+++ b/unitTests.py
@@ -3868,6 +3868,35 @@ class ParseResultsWithNameOr(ParseTestCase):
self.assertEqual(list(expr.parseString('not the bird')['rexp']), 'not the bird'.split())
self.assertEqual(list(expr.parseString('the bird')['rexp']), 'the bird'.split())
+ expr = (expr_a | expr_b)('rexp')
+ expr.runTests("""\
+ not the bird
+ the bird
+ """)
+ self.assertEqual(list(expr.parseString('not the bird')['rexp']), 'not the bird'.split())
+ self.assertEqual(list(expr.parseString('the bird')['rexp']), 'the bird'.split())
+
+ # test compatibility mode, restoring pre-2.3.1 behavior
+ with AutoReset(pp.__compat__, "collect_all_And_tokens"):
+ pp.__compat__.collect_all_And_tokens = False
+ expr_a = pp.Literal('not') + pp.Literal('the') + pp.Literal('bird')
+ expr_b = pp.Literal('the') + pp.Literal('bird')
+ expr = (expr_a ^ expr_b)('rexp')
+ expr.runTests("""\
+ not the bird
+ the bird
+ """)
+ self.assertEqual(expr.parseString('not the bird')['rexp'], 'not')
+ self.assertEqual(expr.parseString('the bird')['rexp'], 'the')
+
+ expr = (expr_a | expr_b)('rexp')
+ expr.runTests("""\
+ not the bird
+ the bird
+ """)
+ self.assertEqual(expr.parseString('not the bird')['rexp'], 'not')
+ self.assertEqual(expr.parseString('the bird')['rexp'], 'the')
+
class EmptyDictDoesNotRaiseException(ParseTestCase):
def runTest(self):
if not PY_3: