annotate python/testasm.py @ 194:b01429a5d695

Fixed test
author Windel Bouwman
date Wed, 29 May 2013 22:36:37 +0200
parents f091e7d70996
children 37ac6c016e0f
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()
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
38 a.parse_line(asmline)
191
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()
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
43 a.parse_line(asmline)
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
44
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
45 def testParse3(self):
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
46 # A label must be optional:
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
47 asmline = 'mov rax, 1'
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
48 a = libasm.Assembler()
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
49 a.parse_line(asmline)
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
50
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
51 if __name__ == '__main__':
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
52 unittest.main()
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
53