Ejemplo n.º 1
0
 def setUp(self):
     self.lexer = Lexer()
Ejemplo n.º 2
0
 def setUp(self):
     self.lexer = Lexer()
Ejemplo n.º 3
0
class TestLexer(unittest.TestCase):
    def setUp(self):
        self.lexer = Lexer()

    def testEmptyInputSetsCursorToEOF(self):
        self.lexer.parse('')
        self.assertEqual(self.lexer.c, EOF)

    def testDoesReset(self):
        c, cursor, string = self.lexer.c, self.lexer.cursor, self.lexer.string
        self.lexer.parse('')
        self.lexer._reset()
        self.assertEqual(c, self.lexer.c)
        self.assertEqual(cursor, self.lexer.cursor)
        self.assertEqual(string, self.lexer.string)

    def testCursorIsPrimed(self):
        self.lexer.parse("foo")
        self.assertEqual(self.lexer.c, 'f')

    def testCanConsume(self):
        self.lexer.parse("foo")
        self.lexer.consume()
        self.assertEqual(self.lexer.c, 'o')
        self.assertEqual(self.lexer.cursor, 1)

    def testCanReachEOF(self):
        self.lexer.parse("f")
        self.lexer.consume()
        self.assertEqual(self.lexer.c, EOF)

    def testPassingInJunk(self):
        self.assertRaises(TypeError, self.lexer.parse, 100)
        self.assertRaises(TypeError, self.lexer.parse, [])
Ejemplo n.º 4
0
class TestLexer(unittest.TestCase):
    def setUp(self):
        self.lexer = Lexer()

    def testEmptyInputSetsCursorToEOF(self):
        self.lexer.parse('')
        self.assertEqual(self.lexer.c, EOF)

    def testDoesReset(self):
        c, cursor, string = self.lexer.c, self.lexer.cursor, self.lexer.string
        self.lexer.parse('')
        self.lexer._reset()
        self.assertEqual(c, self.lexer.c)
        self.assertEqual(cursor, self.lexer.cursor)
        self.assertEqual(string, self.lexer.string)

    def testCursorIsPrimed(self):
        self.lexer.parse("foo")
        self.assertEqual(self.lexer.c, 'f')

    def testCanConsume(self):
        self.lexer.parse("foo")
        self.lexer.consume()
        self.assertEqual(self.lexer.c, 'o')
        self.assertEqual(self.lexer.cursor, 1)

    def testCanReachEOF(self):
        self.lexer.parse("f")
        self.lexer.consume()
        self.assertEqual(self.lexer.c, EOF)

    def testPassingInJunk(self):
        self.assertRaises(TypeError, self.lexer.parse, 100)
        self.assertRaises(TypeError, self.lexer.parse, [])