comparison python/testasm.py @ 193:f091e7d70996

Added even more checks
author Windel Bouwman
date Sun, 26 May 2013 23:58:59 +0200
parents 6b2bec5653f1
children b01429a5d695
comparison
equal deleted inserted replaced
192:6cd6260789a1 193:f091e7d70996
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']
17 self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks) 17 self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks)
18 18
19 def testLex1(self): 19 def testLex1(self):
20 """ Test if lexer correctly maps some tokens """
20 asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID'] 21 asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID']
21 self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks) 22 self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks)
22 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 libasm.tokenize(asmline)], toks)
28
23 def testLex2(self): 29 def testLex2(self):
30 """ Test if lexer fails on a token that is invalid """
24 asmline = '0z4: mov rax, rbx $ ' 31 asmline = '0z4: mov rax, rbx $ '
25 with self.assertRaises(ppci.CompilerError): 32 with self.assertRaises(ppci.CompilerError):
26 list(libasm.tokenize(asmline)) 33 list(libasm.tokenize(asmline))
27 34
28 def testParse(self): 35 def testParse(self):
29 asmline = 'lab1: mov rax, rbx' 36 asmline = 'lab1: mov rax, rbx'
30 a = libasm.Assembler() 37 a = libasm.Assembler()
31 a.assembleLine(asmline) 38 a.assembleLine(asmline)
32 39
40 def testParse2(self):
41 asmline = 'a: mov rax, [rbx + 2]'
42 a = libasm.Assembler()
43 a.assembleLine(asmline)
44
33 if __name__ == '__main__': 45 if __name__ == '__main__':
34 unittest.main() 46 unittest.main()
35 47