diff python/testasm.py @ 200:5e391d9a3381

Split off asm nodes
author Windel Bouwman
date Sun, 09 Jun 2013 16:06:49 +0200
parents a690473b79e2
children d5debbfc0200
line wrap: on
line diff
--- a/python/testasm.py	Fri Jun 07 18:59:57 2013 +0200
+++ b/python/testasm.py	Sun Jun 09 16:06:49 2013 +0200
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 
 import unittest, cProfile
-import ppci
+from ppci import CompilerError
 from asm import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber, tokenize, Assembler
 import msp430
 
@@ -26,7 +26,7 @@
     def testLex2(self):
         """ Test if lexer fails on a token that is invalid """
         asmline = '0z4: mov rax, rbx $ '
-        with self.assertRaises(ppci.CompilerError):
+        with self.assertRaises(CompilerError):
             list(tokenize(asmline))
 
 class AssemblerParsingTestCase(unittest.TestCase):
@@ -79,6 +79,11 @@
         self.a.parse_line('')
     
 class AssemblerOtherTestCase(unittest.TestCase):
+    def testWithoutTarget(self):
+        a = Assembler()
+        with self.assertRaises(CompilerError):
+            a.assemble_line('')
+    @unittest.skip 
     def testX86(self):
         testsrc = """ ; tst
         begin:
@@ -91,16 +96,30 @@
         # Compare with nasm output:
         nasmbytes = [0x48, 0x89, 0xd8, 0x48, 0x31, 0xd9, 0x48, 0xff, 0xc1]
 
-class AssemblerOtherTestCase(unittest.TestCase):
+class AssemblerMSP430TestCase(unittest.TestCase):
     def setUp(self):
-        self.a = Assembler(target=msp430.MSP430())
+        self.t = msp430.MSP430()
+        self.a = Assembler(target=self.t)
+
+    def testMapInstruction(self):
+        i = AInstruction('mov', [ASymbol('r14'), ASymbol('r15')])
+        self.t.mapInstruction(i)
+
+    def testMapOperand(self):
+        o = ASymbol('r14')
+        mo = self.t.mapOperand(o)
+        self.assertEqual(mo, msp430.r14)
+
+    def testMapOperandIndirection(self):
+        o = AUnop('[]', ASymbol('r14'))
+        mo = self.t.mapOperand(o)
 
     def testMov(self):
         line1 = "mov r14, r15"
         self.a.assemble_line(line1)
 
     def testAdd(self):
-        line1 = "addw r14, r15"
+        line1 = "add r14, r15"
         self.a.assemble_line(line1)