diff options
-rw-r--r-- | .travis.yml | 6 | ||||
-rw-r--r-- | examples/lucene_grammar.py | 3 | ||||
-rw-r--r-- | examples/romanNumerals.py | 27 | ||||
-rw-r--r-- | examples/sexpParser.py | 17 | ||||
-rw-r--r-- | pyparsing.py | 4 |
5 files changed, 34 insertions, 23 deletions
diff --git a/.travis.yml b/.travis.yml index ff4477b..0e1f185 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,12 @@ install: script: - python unitTests.py - python simple_unit_tests.py + - python examples/numerics.py + - python examples/lucene_grammar.py + - python examples/TAP.py + - python examples/romanNumerals.py + - python examples/sexpParser.py + - python examples/oc.py after_success: - codecov diff --git a/examples/lucene_grammar.py b/examples/lucene_grammar.py index 0cd7e0d..2791b7c 100644 --- a/examples/lucene_grammar.py +++ b/examples/lucene_grammar.py @@ -317,3 +317,6 @@ success1, _ = expression.runTests(tests) success2, _ = expression.runTests(failtests, failureTests=True)
print(("FAIL", "OK")[success1 and success2])
+
+if not (success1 and success2):
+ raise Exception("failure in lucene grammar parser, check output")
diff --git a/examples/romanNumerals.py b/examples/romanNumerals.py index 536fbb0..0f15ac8 100644 --- a/examples/romanNumerals.py +++ b/examples/romanNumerals.py @@ -52,17 +52,26 @@ def makeRomanNumeral(n): return ret
tests = " ".join(makeRomanNumeral(i) for i in range(1,5000+1))
+roman_int_map = {}
expected = 1
for t,s,e in romanNumeral.scanString(tests):
+ orig = tests[s:e]
if t[0] != expected:
- print("{} {} {}".format("==>", t, tests[s:e]))
+ print("{} {} {}".format("==>", t, orig))
+ roman_int_map[orig] = t[0]
expected += 1
-def test(rn):
- print("{} -> {}".format(rn, romanNumeral.parseString(rn)[0]))
-test("XVI")
-test("XXXIX")
-test("XIV")
-test("XIX")
-test("MCMLXXX")
-test("MMVI")
+def verify_value(s, tokens):
+ expected = roman_int_map[s]
+ if tokens[0] != expected:
+ raise Exception("incorrect value for {} ({}), expected {}".format(s, tokens[0], expected ))
+
+romanNumeral.runTests("""\
+ XVI
+ XXXIX
+ XIV
+ XIX
+ MCMLXXX
+ MMVI
+ """, fullDump=False,
+ postParse=verify_value)
\ No newline at end of file diff --git a/examples/sexpParser.py b/examples/sexpParser.py index 86fb089..123b401 100644 --- a/examples/sexpParser.py +++ b/examples/sexpParser.py @@ -139,8 +139,8 @@ test07 = """(defun factorial (x) (if (zerop x) 1
(* x (factorial (- x 1)))))
"""
-test51 = """(2:XX "abc" (#30# |YWJj|))"""
-test51error = """(3:XX "abc" (#30# |YWJj|))"""
+test51 = """(2:XX "abc" (#03# |YWJj|))"""
+test51error = """(3:XX "abc" (#03# |YWJj|))"""
test52 = """
(and
@@ -153,15 +153,6 @@ test52 = """ # Run tests
t = None
-alltests = [ locals()[t] for t in sorted(locals()) if t.startswith("test") ]
+alltests = [ globals()[t] for t in sorted(locals()) if t.startswith("test") ]
-for t in alltests:
- print('-'*50)
- print(t)
- try:
- sexpr = sexp.parseString(t, parseAll=True)
- pprint.pprint(sexpr.asList())
- except ParseFatalException as pfe:
- print("Error:", pfe.msg)
- print(pfe.markInputline('^'))
- print()
+sexp.runTests(alltests, fullDump=False)
diff --git a/pyparsing.py b/pyparsing.py index 975846c..89c48d9 100644 --- a/pyparsing.py +++ b/pyparsing.py @@ -2454,7 +2454,9 @@ class ParserElement(object): success = success and not failureTests if postParse is not None: try: - out.append(postParse(t, result)) + pp_value = postParse(t, result) + if pp_value is not None: + out.append(str(pp_value)) except Exception as e: out.append("{} failed: {}: {}".format(postParse.__name__, type(e).__name__, e)) except ParseBaseException as pe: |