annotate python/testasm.py @ 191:6b2bec5653f1

Added assembler testset
author Windel Bouwman
date Sun, 26 May 2013 15:28:07 +0200
parents
children f091e7d70996
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):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
20 asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID']
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
21 self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks)
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
22
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
23 def testLex2(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
24 asmline = '0z4: mov rax, rbx $ '
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
25 with self.assertRaises(ppci.CompilerError):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
26 list(libasm.tokenize(asmline))
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
27
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
28 def testParse(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
29 asmline = 'lab1: mov rax, rbx'
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
30 a = libasm.Assembler()
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
31 a.assembleLine(asmline)
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
32
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
33 if __name__ == '__main__':
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
34 unittest.main()
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
35