comparison test/testasm.py @ 318:e84047f29c78

Add burg and yacc initial attempts
author Windel Bouwman
date Tue, 31 Dec 2013 12:38:15 +0100
parents 534b94b40aa8
children 6f4753202b9a
comparison
equal deleted inserted replaced
317:e30a77ae359b 318:e84047f29c78
11 class AssemblerLexingCase(unittest.TestCase): 11 class AssemblerLexingCase(unittest.TestCase):
12 """ Tests the assemblers lexer """ 12 """ Tests the assemblers lexer """
13 13
14 def testLex0(self): 14 def testLex0(self):
15 """ Check if the lexer is OK """ 15 """ Check if the lexer is OK """
16 asmline, toks = 'mov rax, rbx ', ['ID', 'ID', ',', 'ID'] 16 asmline, toks = 'mov rax, rbx ', ['ID', 'ID', ',', 'ID', 'EOF']
17 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks) 17 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
18 18
19 def testLex1(self): 19 def testLex1(self):
20 """ Test if lexer correctly maps some tokens """ 20 """ Test if lexer correctly maps some tokens """
21 asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID'] 21 asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID', 'EOF']
22 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
23
24 def testLex1(self):
25 """ Test if lexer correctly maps some tokens """
26 asmline, toks = 'mov 3.13 0xC 13', ['ID', 'REAL', 'NUMBER', 'NUMBER']
27 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks) 22 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
28 23
29 def testLex2(self): 24 def testLex2(self):
25 """ Test if lexer correctly maps some tokens """
26 asmline, toks = 'mov 3.13 0xC 13', ['ID', 'REAL', 'NUMBER', 'NUMBER', 'EOF']
27 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
28
29 def testLex3(self):
30 """ Test if lexer fails on a token that is invalid """ 30 """ Test if lexer fails on a token that is invalid """
31 asmline = '0z4: mov rax, rbx $ ' 31 asmline = '0z4: mov rax, rbx $ '
32 with self.assertRaises(CompilerError): 32 with self.assertRaises(CompilerError):
33 list(tokenize(asmline)) 33 list(tokenize(asmline))
34 34
79 self.expectTree(asmline, output) 79 self.expectTree(asmline, output)
80 80
81 def testParse6(self): 81 def testParse6(self):
82 # A line can be empty 82 # A line can be empty
83 self.a.parse_line('') 83 self.a.parse_line('')
84 84
85 85
86 class AssemblerOtherTestCase(unittest.TestCase): 86 class AssemblerOtherTestCase(unittest.TestCase):
87 def testWithoutTarget(self): 87 def testWithoutTarget(self):
88 a = Assembler() 88 a = Assembler()
89 with self.assertRaises(CompilerError): 89 with self.assertRaises(CompilerError):