mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 09:43:06 +00:00
660276a0b8
I'm not a fan of 100% of the Black coding style, but I've spent too much time manually formatting Python code, so let's just pull the trigger.
31 lines
1000 B
Python
31 lines
1000 B
Python
import unittest
|
|
|
|
from tests.libdrgn import drgn_test_lexer_func, Lexer
|
|
|
|
|
|
class TestLexer(unittest.TestCase):
|
|
def test_pop(self):
|
|
lexer = Lexer(drgn_test_lexer_func, "12345")
|
|
for i in range(5):
|
|
self.assertEqual(lexer.pop().kind, ord("1") + i)
|
|
self.assertEqual(lexer.pop().kind, 0)
|
|
|
|
def test_push(self):
|
|
lexer = Lexer(drgn_test_lexer_func, "12345")
|
|
tokens = []
|
|
for i in range(4):
|
|
tokens.append(lexer.pop())
|
|
while tokens:
|
|
lexer.push(tokens.pop())
|
|
for i in range(5):
|
|
self.assertEqual(lexer.pop().kind, ord("1") + i)
|
|
self.assertEqual(lexer.pop().kind, 0)
|
|
|
|
def test_peek(self):
|
|
lexer = Lexer(drgn_test_lexer_func, "12345")
|
|
for i in range(5):
|
|
self.assertEqual(lexer.peek().kind, ord("1") + i)
|
|
self.assertEqual(lexer.pop().kind, ord("1") + i)
|
|
self.assertEqual(lexer.peek().kind, 0)
|
|
self.assertEqual(lexer.pop().kind, 0)
|