annotate 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
rev   line source
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
1 #!/usr/bin/python
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
2
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
3 import unittest
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
4 import libasm
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
5 import ppci
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
6
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
7 class AssemblerTestCase(unittest.TestCase):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
8 """
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
9 Tests the assembler parts
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
10 """
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
11 def setUp(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
12 pass
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
13
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
14 def testLex0(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
15 """ Check if the lexer is OK """
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
16 asmline, toks = 'mov rax, rbx ', ['ID', 'ID', ',', 'ID']
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
17 self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks)
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
18
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
19 def testLex1(self):
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
20 """ Test if lexer correctly maps some tokens """
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
21 asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID']
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
22 self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks)
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
23
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
24 def testLex1(self):
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
25 """ Test if lexer correctly maps some tokens """
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
26 asmline, toks = 'mov 3.13 0xC 13', ['ID', 'REAL', 'NUMBER', 'NUMBER']
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
27 self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks)
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
28
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
29 def testLex2(self):
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
30 """ Test if lexer fails on a token that is invalid """
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
31 asmline = '0z4: mov rax, rbx $ '
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
32 with self.assertRaises(ppci.CompilerError):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
33 list(libasm.tokenize(asmline))
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
34
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
35 def testParse(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
36 asmline = 'lab1: mov rax, rbx'
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
37 a = libasm.Assembler()
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
38 a.assembleLine(asmline)
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
39
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
40 def testParse2(self):
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
41 asmline = 'a: mov rax, [rbx + 2]'
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
42 a = libasm.Assembler()
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
43 a.assembleLine(asmline)
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
44
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
45 if __name__ == '__main__':
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
46 unittest.main()
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
47