summaryrefslogtreecommitdiff
path: root/simple_unit_tests.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2018-09-19 23:26:29 -0500
committerptmcg <ptmcg@austin.rr.com>2018-09-19 23:26:29 -0500
commit8db18bde0c78b9162f64ec66eed5de84f5fdcf03 (patch)
treecfd50361478083355943f50d634776e366a2a453 /simple_unit_tests.py
parent5e5c94a6f0e907679ecd4e5aeecffd12edd48889 (diff)
downloadpyparsing-git-8db18bde0c78b9162f64ec66eed5de84f5fdcf03.tar.gz
simple_unit_tests with Dict and combination of parse action and condition
Diffstat (limited to 'simple_unit_tests.py')
-rw-r--r--simple_unit_tests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/simple_unit_tests.py b/simple_unit_tests.py
index 4c5c017..2345bc2 100644
--- a/simple_unit_tests.py
+++ b/simple_unit_tests.py
@@ -192,6 +192,15 @@ class TestGroups(PyparsingExpressionTestCase):
text = "range=5280 long=-138.52 lat=46.91",
expected_list = [['range', 5280], ['long', -138.52], ['lat', 46.91]],
),
+ PpTestSpec(
+ desc = "Define multiple results names in groups - use Dict to define results names using parsed keys",
+ expr = pp.Dict(pp.OneOrMore(pp.Group(pp.Word(pp.alphas, pp.alphanums)("key")
+ + pp.Suppress('=')
+ + pp.pyparsing_common.number("value")))),
+ text = "range=5280 long=-138.52 lat=46.91",
+ expected_list = [['range', 5280], ['long', -138.52], ['lat', 46.91]],
+ expected_dict = {'lat': 46.91, 'long': -138.52, 'range': 5280}
+ ),
]
class TestParseAction(PyparsingExpressionTestCase):
@@ -225,6 +234,13 @@ class TestParseCondition(PyparsingExpressionTestCase):
text = "14 35 77 12 28",
expected_list = ['14', '35', '77'],
),
+ PpTestSpec(
+ desc = "Separate conversion to int and condition into separate parse action/conditions",
+ expr = pp.OneOrMore(pp.Word(pp.nums).addParseAction(lambda t: int(t[0]))
+ .addCondition(lambda t: t[0] % 7 == 0)),
+ text = "14 35 77 12 28",
+ expected_list = [14, 35, 77],
+ ),
]