diff python/testasm.py @ 191:6b2bec5653f1

Added assembler testset
author Windel Bouwman
date Sun, 26 May 2013 15:28:07 +0200
parents
children f091e7d70996
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/testasm.py	Sun May 26 15:28:07 2013 +0200
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+import unittest
+import libasm
+import ppci
+
+class AssemblerTestCase(unittest.TestCase):
+    """ 
+        Tests the assembler parts
+    """
+    def setUp(self):
+        pass
+
+    def testLex0(self):
+        """ Check if the lexer is OK """
+        asmline, toks = 'mov rax, rbx ', ['ID', 'ID', ',', 'ID']
+        self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks)
+
+    def testLex1(self):
+        asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID']
+        self.assertSequenceEqual([tok.typ for tok in libasm.tokenize(asmline)], toks)
+
+    def testLex2(self):
+        asmline = '0z4: mov rax, rbx $ '
+        with self.assertRaises(ppci.CompilerError):
+            list(libasm.tokenize(asmline))
+
+    def testParse(self):
+        asmline = 'lab1: mov rax, rbx'
+        a = libasm.Assembler()
+        a.assembleLine(asmline)
+
+if __name__ == '__main__':
+    unittest.main()
+