diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2018-12-30 09:32:30 -0600 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2018-12-30 09:32:30 -0600 |
commit | 3d1ada6a3379e48f8da34971da8be22be39324e5 (patch) | |
tree | ba46c1aa082574ee8b198389db76dce1c3afdec6 /examples/romanNumerals.py | |
parent | c3bb1856f94fe393d209d3dd95af718526497a04 (diff) | |
download | pyparsing-git-3d1ada6a3379e48f8da34971da8be22be39324e5.tar.gz |
Update Travis-CI scripts to include examples; fix bug in runTests if postParse function returns None (or any non-str value)
Diffstat (limited to 'examples/romanNumerals.py')
-rw-r--r-- | examples/romanNumerals.py | 27 |
1 files changed, 18 insertions, 9 deletions
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 |