diff options
author | ptmcg <ptmcg@austin.rr.com> | 2018-10-30 18:04:03 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2018-10-30 18:04:03 -0500 |
commit | fbafa927cbc5defdd060adeb08ba4082bbc1d71f (patch) | |
tree | 36c9c8ee658bb07a024b07954d636430f40aeeb8 /unitTests.py | |
parent | e308005e9645303487451909d00079187edf09e6 (diff) | |
download | pyparsing-git-fbafa927cbc5defdd060adeb08ba4082bbc1d71f.tar.gz |
Add unit test for indentedBlock expression
Diffstat (limited to 'unitTests.py')
-rw-r--r-- | unitTests.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/unitTests.py b/unitTests.py index 184a8ac..31832b7 100644 --- a/unitTests.py +++ b/unitTests.py @@ -3631,6 +3631,43 @@ class UnicodeTests(ParseTestCase): self.assertTrue(result.asList() == [u'Καλημέρα', ',', u'κόσμε', '!'],
"Failed to parse Greek 'Hello, World!' using pyparsing_unicode.Greek.alphas")
+class IndentedBlockTest(ParseTestCase):
+ # parse pseudo-yaml indented text
+ def runTest(self):
+ if pp.ParserElement.packrat_cache:
+ print("cannot test indentedBlock with packrat enabled")
+ return
+ import textwrap
+
+ EQ = pp.Suppress('=')
+ stack = [1]
+ key = pp.pyparsing_common.identifier
+ value = pp.Forward()
+ key_value = key + EQ + value
+ compound_value = pp.Dict(pp.ungroup(pp.indentedBlock(key_value, stack)))
+ value <<= pp.pyparsing_common.integer | pp.QuotedString("'") | compound_value
+ parser = pp.Dict(pp.OneOrMore(pp.Group(key_value)))
+
+ text = """\
+ a = 100
+ b = 101
+ c =
+ c1 = 200
+ c2 =
+ c21 = 999
+ c3 = 'A horse, a horse, my kingdom for a horse'
+ d = 505
+ """
+ text = textwrap.dedent(text)
+ print_(text)
+
+ result = parser.parseString(text)
+ print_(result.dump())
+ self.assertEqual(result.a, 100, "invalid indented block result")
+ self.assertEqual(result.c.c1, 200, "invalid indented block result")
+ self.assertEqual(result.c.c2.c21, 999, "invalid indented block result")
+
+
class MiscellaneousParserTests(ParseTestCase):
def runTest(self):
|