diff options
| author | 2023-02-08 13:56:39 +0000 | |
|---|---|---|
| committer | 2023-02-08 13:56:39 +0000 | |
| commit | e044a7b457da7468d2fb49ef658549ea1b4861af (patch) | |
| tree | a7cdbb3a8b76e6fba3e935456672240d8d366f52 /asm/test.py | |
| parent | python ffi: test parsing (diff) | |
test refactoring
Diffstat (limited to 'asm/test.py')
| -rw-r--r-- | asm/test.py | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/asm/test.py b/asm/test.py index dc07655..b9d6520 100644 --- a/asm/test.py +++ b/asm/test.py @@ -2,17 +2,57 @@ from creole import * import unittest import ffi -class ProgramTest(unittest.TestCase): - def test_oneline(self): +class PushTest(unittest.TestCase): + def test_parse_push_reg(self): p = Program() - p.parse_asm_line("PUSH r0") + p.parse_asm_line("push r5") b = p() self.assertEqual(b, b'\x01\xC2\x80\x00') + ins = ffi.parse_line(b) + self.assertEqual(ins[0], instructions["push"].opcode) + self.assertEqual(ins[1][0], (1,5)) + + def test_parse_push_catch_typecheck_push_imm(self): + p = Program() + with self.assertRaises(TypecheckException) as cm: + p.parse_asm_line("push 0") + self.assertEqual(cm.exception.argtype, ArgType.REG) + self.assertEqual(cm.exception.sarg, '0') + self.assertEqual(cm.exception.i, 0) + self.assertEqual(cm.exception.opcode, 1) + + def test_parse_push_catch_typecheck_push_lab(self): + p = Program() + with self.assertRaises(TypecheckException) as cm: + p.parse_asm_line("push l0") + self.assertEqual(cm.exception.argtype, ArgType.REG) + self.assertEqual(cm.exception.sarg, 'l0') + self.assertEqual(cm.exception.i, 0) + self.assertEqual(cm.exception.opcode, 1) + + def test_parse_push_catch_typecheck_argument_overflow(self): + p = Program() + with self.assertRaises(TypecheckLenException) as cm: + p.parse_asm_line("push r1 r2") + self.assertEqual(cm.exception.opcode, 1) + self.assertEqual(cm.exception.insargs, ["r1", "r2"]) + self.assertEqual(cm.exception.argtypelen, 1) + + def test_parse_push_catch_typecheck_argument_underflow(self): + p = Program() + with self.assertRaises(TypecheckLenException) as cm: + p.parse_asm_line("push") + self.assertEqual(cm.exception.opcode, 1) + self.assertEqual(cm.exception.insargs, []) + self.assertEqual(cm.exception.argtypelen, 1) + def test_large_reg(self): p = Program(regnum=0x8000000) p.parse_asm_line("PUSH r134217727") b = p() self.assertEqual(b, b'\x01\xFC\x87\xbf\xbf\xbf\xbf\x00') + +class ProgramTest(unittest.TestCase): def test_two(self): p = Program() p.parse_asm_line("PUSH r1") @@ -39,12 +79,14 @@ class ProgramTest(unittest.TestCase): b = p() self.assertEqual(b, b_ex) - def test_parse_reg(self): + def test_parse_imm(self): p = Program() - p.parse_asm_line("push r5") + p.parse_asm_line("add r1 23 3648") ins = ffi.parse_line(p()) - self.assertEqual(ins[0], instructions["push"].opcode) - self.assertEqual(ins[1][0], (1,5)) + self.assertEqual(ins[0], instructions["add"].opcode) + self.assertEqual(ins[1][0], (1,1)) + self.assertEqual(ins[1][1], (0,23)) + self.assertEqual(ins[1][2], (0,3648)) if __name__ == "__main__": unittest.main() |
