summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2020-04-03 20:25:43 -0500
committerptmcg <ptmcg@austin.rr.com>2020-04-03 20:25:43 -0500
commit8d36d7709b40ad1a1fb309bdba8c785c744d9c08 (patch)
tree9e6fa12e764d2aa9ace69f8563b22b7f6dbdec61 /tests
parent61af31e9b4c29be7d88d5a7ff75252bc9ab55253 (diff)
downloadpyparsing-git-8d36d7709b40ad1a1fb309bdba8c785c744d9c08.tar.gz
Enhanced error messages and error locations when parsing fails on the Keyword or CaselessKeyword classes due to the presence of a preceding or trailing keyword character. See issue #201.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_unit.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py
index cda4e0d..de06ddf 100644
--- a/tests/test_unit.py
+++ b/tests/test_unit.py
@@ -2417,7 +2417,7 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
values_set = set(result.values())
print(values_set)
expected = {"spam", "eggs"}
- self.assertEquals(
+ self.assertEqual(
values_set, expected, msg="issue calling ParseResults.values()"
)
@@ -5497,6 +5497,67 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase):
False, "failed to match keyword using updated keyword chars"
)
+ def testLiteralVsKeyword(self):
+
+ integer = ppc.integer
+ literal_expr = integer + pp.Literal("start") + integer
+ keyword_expr = integer + pp.Keyword("start") + integer
+ caseless_keyword_expr = integer + pp.CaselessKeyword("START") + integer
+ word_keyword_expr = (
+ integer + pp.Word(pp.alphas, asKeyword=True).setName("word") + integer
+ )
+
+ print()
+ test_string = "1 start 2"
+ print(test_string)
+ print(literal_expr, literal_expr.parseString(test_string, parseAll=True))
+ print(keyword_expr, keyword_expr.parseString(test_string, parseAll=True))
+ print(
+ caseless_keyword_expr,
+ caseless_keyword_expr.parseString(test_string, parseAll=True),
+ )
+ print(
+ word_keyword_expr, word_keyword_expr.parseString(test_string, parseAll=True)
+ )
+ print()
+
+ test_string = "3 start4"
+ print(test_string)
+ print(literal_expr, literal_expr.parseString(test_string, parseAll=True))
+ with self.assertRaisesParseException(
+ msg="failed to fail matching keyword using updated keyword chars"
+ ):
+ print(keyword_expr.parseString(test_string, parseAll=True))
+
+ with self.assertRaisesParseException(
+ msg="failed to fail matching keyword using updated keyword chars"
+ ):
+ print(caseless_keyword_expr.parseString(test_string, parseAll=True))
+
+ with self.assertRaisesParseException(
+ msg="failed to fail matching keyword using updated keyword chars"
+ ):
+ print(word_keyword_expr.parseString(test_string, parseAll=True))
+ print()
+
+ test_string = "5start 6"
+ print(test_string)
+ print(literal_expr.parseString(test_string, parseAll=True))
+ with self.assertRaisesParseException(
+ msg="failed to fail matching keyword using updated keyword chars"
+ ):
+ print(keyword_expr.parseString(test_string, parseAll=True))
+
+ with self.assertRaisesParseException(
+ msg="failed to fail matching keyword using updated keyword chars"
+ ):
+ print(caseless_keyword_expr.parseString(test_string, parseAll=True))
+
+ with self.assertRaisesParseException(
+ msg="failed to fail matching keyword using updated keyword chars"
+ ):
+ print(word_keyword_expr.parseString(test_string, parseAll=True))
+
def testCol(self):
test = "*\n* \n* ALF\n*\n"