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:
parent
a5b82cf534
commit
11a66ec69c
@ -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
|
||||
|
@ -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'))
|
||||
|
Loading…
Reference in New Issue
Block a user