Skip to content

Commit 2d99dd9

Browse files
committed
bugfix: remove dummy spaces from asm code
This prevents errors in later preprocessing. Also add some tests. Names the test file `test_optimizer_asm` to avoid name clash with other `test_asm`.
1 parent fa477b3 commit 2d99dd9

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

arch/zx48k/optimizer/asm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Asm(object):
1313
"""
1414
def __init__(self, asm):
1515
assert isinstance(asm, str)
16+
asm = asm.strip()
17+
assert asm, "Empty instruction '{}'".format(asm)
1618
self.inst = Asm.inst(asm)
1719
self.oper = Asm.opers(asm)
1820
self.asm = '{} {}'.format(self.inst, ' '.join(asm.split(' ', 1)[1:])).strip()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
from arch.zx48k.optimizer import asm
5+
6+
7+
class TestASM(unittest.TestCase):
8+
""" Tests optimizer Asm class
9+
"""
10+
def test_spaces(self):
11+
a = asm.Asm(' nop \t\n')
12+
self.assertEqual(a.asm, 'nop')
13+
14+
def test_raises_error_on_empty_instruction(self):
15+
self.assertRaises(AssertionError, asm.Asm, ' \t \n')
16+
17+
def test_unknown_instruction(self):
18+
a = asm.Asm(' unknown instr ')
19+
self.assertEqual(a.bytes, ())

0 commit comments

Comments
 (0)