def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", ParseClassTestCase2.Word) self.assertEqual(type(r[1]), ParseClassTestCase2.Word) self.assertEqual(r[1], "hello") self.assertTrue(r[1].polished) self.assertEqual(r[1].comma, None)
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", ParseListTestCase1.Chars) self.assertEqual(r, ( 'world', ParseListTestCase1.Chars(['h', 'e', 'l', 'l', 'o'])) ) self.assertEqual(r[1].comma, None)
def runTest(self): parser = pypeg2.Parser() parser.comment = pypeg2.comment_c t, parms = parser.parse("x=23 /* Illuminati */, y=42 /* the answer */;", Parms) self.assertEqual(parms["x"].value, 23) self.assertEqual(parms["y"].value, 42) self.assertEqual(parms.fullstop, False) self.assertEqual(parms.semicolon, True)
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", pypeg2.attr("some", pypeg2.Symbol)) self.assertEqual( r, ( ', world', pypeg2.attr.Class(name='some', thing=pypeg2.Symbol('hello'), subtype=None) ) )
def MakeTest(self, exp, caseNo: int): test = Test() parser = pypeg2.Parser() test.StartTest(caseNo, 1, 100, 'PEG', lambda w: self.TestPositive(exp, parser, w), lambda w: self.TestNegative(exp, w)) test.StartTest(caseNo, 101, 1000, 'PEG', lambda w: self.TestPositive(exp, parser, w), lambda w: self.TestNegative(exp, w)) test.StartTest(caseNo, 1001, 10000, 'PEG', lambda w: self.TestPositive(exp, parser, w), lambda w: self.TestNegative(exp, w)) test.StartTest(caseNo, 10001, 100000, 'PEG', lambda w: self.TestPositive(exp, parser, w), lambda w: self.TestNegative(exp, w))
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", (pypeg2.name(), ",", pypeg2.name())) self.assertEqual( r, ( '', [ pypeg2.attr.Class(name='name', thing=pypeg2.Symbol('hello'), subtype=None), pypeg2.attr.Class(name='name', thing=pypeg2.Symbol('world'), subtype=None) ] ) )
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", pypeg2.Symbol) self.assertEqual(r, (", world", pypeg2.Symbol("hello")))
def runTest(self): parser = pypeg2.Parser() with self.assertRaises(SyntaxError): r = parser.parse("hello, world", re.compile(r"\d", re.U))
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", re.compile(r"h.[lx]l\S", re.U)) self.assertEqual(r, (", world", "hello"))
def runTest(self): parser = pypeg2.Parser() with self.assertRaises(SyntaxError): r = parser.parse(", world", pypeg2.K("hallo")) pypeg2.Keyword.table[pypeg2.K("hallo")]
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hallo, world", pypeg2.K("hallo")) self.assertEqual(r, (", world", None)) pypeg2.Keyword.table[pypeg2.K("hallo")]
def runTest(self): parser = pypeg2.Parser() with self.assertRaises(SyntaxError): r = parser.parse("hello, world", "world")
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", (5, re.compile(r"\w", re.U))) self.assertEqual(r, (', world', ['h', 'e', 'l', 'l', 'o']))
def runTest(self): parser = pypeg2.Parser() with self.assertRaises(pypeg2.GrammarTypeError): parser.parse("hello, world", 23)
def runTest(self): parser = pypeg2.Parser() with self.assertRaises(SyntaxError): t, r = parser.parse("float", EnumTest)
def runTest(self): parser = pypeg2.Parser() with self.assertRaises(ValueError): parser.parse("hello, world", (-23, "x"))
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", pypeg2.maybe_some(re.compile(r"\d", re.U))) self.assertEqual(r, ('hello, world', []))
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", ParseClassTestCase1.Word) self.assertEqual(type(r[1]), ParseClassTestCase1.Word) self.assertEqual(r[1], "hello")
def runTest(self): parser = pypeg2.Parser() with self.assertRaises(SyntaxError): r = parser.parse("hello, world", ParseListTestCase2.Digits)
def runTest(self): parser = pypeg2.Parser() with self.assertRaises(SyntaxError): r = parser.parse(", world", pypeg2.Symbol)
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", "hello") self.assertEqual(r, (", world", None))
def runTest(self): parser = pypeg2.Parser() t, r = parser.parse("int", EnumTest) self.assertEqual(r, "int")
def runTest(self): parser = pypeg2.Parser() r = parser.parse("hello, world", [re.compile(r"\d+", re.U), pypeg2.word]) self.assertEqual(r, (', world', 'hello'))