diff options
author | ptmcg <ptmcg@austin.rr.com> | 2018-10-02 21:18:01 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2018-10-02 21:18:01 -0500 |
commit | a3f0595b570a2e8e69c68afea6fdff810c7134a8 (patch) | |
tree | 384882b8da78d5b62550ab297d214fb8903a33d4 | |
parent | c2842b1cae58c09c58110159c91ff06c1a22400b (diff) | |
download | pyparsing-git-a3f0595b570a2e8e69c68afea6fdff810c7134a8.tar.gz |
add a few more simple unit tests
-rw-r--r-- | simple_unit_tests.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/simple_unit_tests.py b/simple_unit_tests.py index acf75ea..b2a6dc9 100644 --- a/simple_unit_tests.py +++ b/simple_unit_tests.py @@ -125,6 +125,12 @@ class TestCaselessLiteral(PyparsingExpressionTestCase): text = "red Green BluE blue GREEN green rEd", expected_list = ['RED', 'GREEN', 'BLUE', 'BLUE', 'GREEN', 'GREEN', 'RED'], ), + PpTestSpec( + desc = "Match colors, converting to consistent case - use generator to define expresssions for MatchFirst", + expr = pp.OneOrMore(pp.MatchFirst(pp.CaselessLiteral(color) for color in "RED GREEN BLUE".split())), + text = "red Green BluE blue GREEN green rEd", + expected_list = ['RED', 'GREEN', 'BLUE', 'BLUE', 'GREEN', 'GREEN', 'RED'], + ), ] class TestWord(PyparsingExpressionTestCase): @@ -158,6 +164,12 @@ class TestRepetition(PyparsingExpressionTestCase): expected_list = ['xx', 'y', 'xx', 'yy', 'xx', 'y', 'x', 'y', 'xxx', 'y'], ), PpTestSpec( + desc = "Match several words, skipping whitespace", + expr = pp.OneOrMore(pp.Word("x") | pp.Word("y")), + text = "x x y xxy yxx y xyx xxy", + expected_list = ['x', 'x', 'y', 'xx', 'y', 'y', 'xx', 'y', 'x', 'y', 'x', 'xx', 'y'], + ), + PpTestSpec( desc = "Match words and numbers - show use of results names to collect types of tokens", expr = pp.OneOrMore(pp.Word(pp.alphas)("alpha*") | pp.pyparsing_common.integer("int*")), text = "sdlfj23084ksdfs08234kjsdlfkjd0934", @@ -223,6 +235,16 @@ class TestGroups(PyparsingExpressionTestCase): expected_list = [['range', 5280], ['long', -138.52], ['lat', 46.91]], expected_dict = {'lat': 46.91, 'long': -138.52, 'range': 5280} ), + PpTestSpec( + desc = "Define multiple value types", + expr = pp.Dict(pp.OneOrMore(pp.Group(pp.Word(pp.alphas) + + EQ + + (pp.pyparsing_common.number | pp.oneOf("True False") | pp.QuotedString("'")) + ))), + text = "long=-122.47 lat=37.82 public=True name='Golden Gate Bridge'", + expected_list = [['long', -122.47], ['lat', 37.82], ['public', 'True'], ['name', 'Golden Gate Bridge']], + expected_dict = {'long': -122.47, 'lat': 37.82, 'public': 'True', 'name': 'Golden Gate Bridge'} + ), ] class TestParseAction(PyparsingExpressionTestCase): |