1
0
mirror of https://github.com/mnaberez/py65.git synced 2025-01-04 01:30:18 +00:00

Raise an exception when assembly fails

This commit is contained in:
Mike Naberezny 2012-11-18 17:05:12 -08:00
parent a5b82cf534
commit 11a66ec69c
2 changed files with 167 additions and 155 deletions

View File

@ -68,7 +68,7 @@ class Assembler:
def assemble(self, statement, pc=0000):
""" Assemble the given assembly language statement. If the statement
uses relative addressing, the program counter (pc) must also be given.
The result is a list of bytes, or None if the assembly failed.
The result is a list of bytes. Raises when assembly fails.
"""
opcode, operands = self.normalize_and_split(statement)
@ -99,7 +99,7 @@ class Assembler:
return bytes
# assembly failed
return None
raise SyntaxError(statement)
def normalize_and_split(self, statement):
""" Given an assembly language statement like "lda $c12,x", normalize

View File

@ -5,6 +5,18 @@ from py65.assembler import Assembler
from py65.utils.addressing import AddressParser
class AssemblerTests(unittest.TestCase):
def test_assemble_bad_syntax_raises_syntaxerror(self):
self.assertRaises(SyntaxError,
self.assemble, 'foo')
def test_assemble_bad_label_raises_keyerror(self):
self.assertRaises(KeyError,
self.assemble, 'lda foo')
def test_assemble_bad_number_raises_overflowerror(self):
self.assertRaises(OverflowError,
self.assemble, 'lda #$fff')
def test_assembles_00(self):
self.assertEqual([0x00],
self.assemble('BRK'))