def runTest(self):
from pyparsing import nestedExpr, Literal, Regex, restOfLine, quotedString<EOL>print_("<STR_LIT>")<EOL>teststring = "<STR_LIT>"<EOL>expr = nestedExpr()<EOL>expected = [[['<STR_LIT>', '<STR_LIT:+>', '<STR_LIT>'], '<STR_LIT>']]<EOL>result = expr.parseString(teststring)<EOL>print_(result.dump())<EOL>self.assertEqual(result.asList(), expected, "<STR_LIT>" % (expected, result))<EOL>print_("<STR_LIT>")<EOL>opener = "<STR_LIT:[>"<EOL>teststring = test_string = "<STR_LIT>"<EOL>expected = [[['<STR_LIT>', '<STR_LIT:+>', '<STR_LIT>'], '<STR_LIT>']]<EOL>expr = nestedExpr("<STR_LIT:[>")<EOL>result = expr.parseString(teststring)<EOL>print_(result.dump())<EOL>self.assertEqual(result.asList(), expected, "<STR_LIT>" % (expected, result))<EOL>print_("<STR_LIT>")<EOL>teststring = test_string = "<STR_LIT>"<EOL>expected = [[['<STR_LIT>', '<STR_LIT:+>', '<STR_LIT>'], '<STR_LIT>']]<EOL>expr = nestedExpr(closer="<STR_LIT:]>")<EOL>result = expr.parseString(teststring)<EOL>print_(result.dump())<EOL>self.assertEqual(result.asList(), expected, "<STR_LIT>" % (expected, result))<EOL>print_("<STR_LIT>")<EOL>opener,closer = list(map(Literal, "<STR_LIT>".split()))<EOL>expr = nestedExpr(opener, closer,<EOL>content=Regex(r"<STR_LIT>"))<EOL>teststring = "<STR_LIT>"<EOL>expected = [[['<STR_LIT>', '<STR_LIT:+>', '<STR_LIT>'], '<STR_LIT>']]<EOL>result = expr.parseString(teststring)<EOL>print_(result.dump())<EOL>self.assertEqual(result.asList(), expected, "<STR_LIT>" % (expected, result))<EOL>print_("<STR_LIT>")<EOL>comment = Regex(r"<STR_LIT>")<EOL>teststring ="""<STR_LIT>"""<EOL>expected = [['<STR_LIT>', [['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']], '<STR_LIT>',['<STR_LIT>', '<STR_LIT>']]]<EOL>expr = nestedExpr(ignoreExpr=comment)<EOL>result = expr.parseString(teststring)<EOL>print_(result.dump())<EOL>self.assertEqual(result.asList(), expected , "<STR_LIT>" % (expected, result))<EOL>print_("<STR_LIT>")<EOL>comment = '<STR_LIT>' + restOfLine<EOL>teststring ="""<STR_LIT>"""<EOL>expected = [['<STR_LIT>', [['<STR_LIT>', '<STR_LIT>']], '<STR_LIT>', '<STR_LIT>',<EOL>['<STR_LIT>', '<STR_LIT>']]]<EOL>expr = nestedExpr(ignoreExpr=(comment ^ quotedString))<EOL>result = expr.parseString(teststring)<EOL>print_(result.dump())<EOL>self.assertEqual(result.asList(), expected ,<EOL>"<STR_LIT>" % (expected, result))<EOL>
This unit test checks nestedExpr in these ways:
- use of default arguments
- use of non-default arguments (such as a pyparsing-defined comment
  expression in place of quotedString)
- use of a custom content expression
- use of a pyparsing expression for opener and closer is *OPTIONAL*
- use of input data containing nesting delimiters
- correct grouping of parsed tokens according to nesting of opening
  and closing delimiters in the input string

(Unit test written by christoph... as part of the Google Highly Open Participation Contest)