Skip to content

Instantly share code, notes, and snippets.

@thomasst
Created April 16, 2013 21:40
Show Gist options
  • Save thomasst/5399884 to your computer and use it in GitHub Desktop.
Save thomasst/5399884 to your computer and use it in GitHub Desktop.
from pyparsing import *
import unittest
unicode_printables = u''.join(unichr(c) for c in xrange(65536)
if not unichr(c).isspace())
word = Word(unicode_printables)
class ParserTestCase(unittest.TestCase):
""" Tests the internals of the parser. """
def assertMatch(self, parser, input):
parser.parseString(input, parseAll=True)
def assertNoMatch(self, parser, input):
try:
parser.parseString(input, parseAll=True)
except ParseException:
pass
else:
raise ValueError('match should fail', input)
def test_word(self):
self.assertMatch(word, 'john')
self.assertNoMatch(word, 'john taylor')
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment