1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-09-29 22:56:17 +00:00

Improve error handling in tilde command

This commit is contained in:
Mike Naberezny 2012-11-21 18:26:24 -08:00
parent 5adeb310d7
commit 222c324fa6
2 changed files with 21 additions and 8 deletions

View File

@ -442,16 +442,21 @@ class Monitor(cmd.Cmd):
self._output("Display a number in decimal, hex, octal, and binary.")
def do_tilde(self, args):
if args == '':
return self.help_tilde()
try:
num = self._address_parser.number(args)
except ValueError:
self._output("Syntax error: %s" % args)
return
self._output("+%u" % num)
self._output("$" + self.byteFmt % num)
self._output("%04o" % num)
self._output(itoa(num, 2).zfill(8))
self._output("+%u" % num)
self._output("$" + self.byteFmt % num)
self._output("%04o" % num)
self._output(itoa(num, 2).zfill(8))
except KeyError:
self._output("Bad label: %s" % args)
except OverflowError:
self._output("Overflow error: %s" % args)
except SyntaxError:
self._output("Syntax error: %s" % statement)
def help_registers(self):
self._output("registers[<name>=<value> [, <name>=<value>]*]")

View File

@ -804,6 +804,14 @@ class MonitorTests(unittest.TestCase):
expected = "+16\n$10\n0020\n00010000\n"
self.assertTrue(out.startswith(expected))
def test_do_tilde_with_no_arg_shows_help(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon.do_tilde('')
out = stdout.getvalue()
expected = "~ <number>"
self.assertTrue(out.startswith(expected))
def test_help_tilde(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)