mirror of
https://github.com/mnaberez/py65.git
synced 2024-09-06 10:54:32 +00:00
Make address_for() more like label_for(), add tests
This commit is contained in:
parent
0eb28bf4dc
commit
d50458ca85
@ -124,6 +124,20 @@ class AddressParserTests(unittest.TestCase):
|
||||
parser.labels = {'foo': 0xFFFFFF}
|
||||
self.assertRaises(OverflowError, parser.number, 'foo+5')
|
||||
|
||||
# address_for
|
||||
|
||||
def test_address_for_returns_label(self):
|
||||
parser = AddressParser(labels={'chrout': 0xFFD2})
|
||||
self.assertEqual(0xffd2, parser.address_for('chrout'))
|
||||
|
||||
def test_address_for_returns_none_by_default(self):
|
||||
parser = AddressParser(labels={})
|
||||
self.assertEqual(None, parser.address_for('chrout'))
|
||||
|
||||
def test_adderss_for_returns_alternate_default(self):
|
||||
parser = AddressParser(labels={})
|
||||
self.assertEqual('foo', parser.address_for('chrout', 'foo'))
|
||||
|
||||
# label_for
|
||||
|
||||
def test_label_for_returns_label(self):
|
||||
|
@ -27,6 +27,11 @@ class AddressParser(object):
|
||||
|
||||
maxwidth = property(_get_maxwidth, _set_maxwidth)
|
||||
|
||||
def address_for(self, label, default=None):
|
||||
"""Given a label, return the corresponding address or a default.
|
||||
"""
|
||||
return self.labels.get(label, default)
|
||||
|
||||
def label_for(self, address, default=None):
|
||||
"""Given an address, return the corresponding label or a default.
|
||||
"""
|
||||
@ -35,10 +40,6 @@ class AddressParser(object):
|
||||
return label
|
||||
return default
|
||||
|
||||
def address_for(self, label):
|
||||
"""Given a label, return the corresponding address or None."""
|
||||
return self.labels.get(label, None)
|
||||
|
||||
def number(self, num):
|
||||
"""Parse a string containing a label or number into an address.
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user