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

Add "q" as a shortcut for "quit"

This commit is contained in:
Mike Naberezny 2012-01-10 09:58:45 -08:00
parent 7b48d3e794
commit b55d045eff
2 changed files with 74 additions and 65 deletions

View File

@ -127,6 +127,7 @@ class Monitor(cmd.Cmd):
'g': 'goto', 'g': 'goto',
'l': 'load', 'l': 'load',
'm': 'mem', 'm': 'mem',
'q': 'quit',
'r': 'registers', 'r': 'registers',
'ret': 'return', 'ret': 'return',
'rad': 'radix', 'rad': 'radix',

View File

@ -9,7 +9,7 @@ from StringIO import StringIO
class MonitorTests(unittest.TestCase): class MonitorTests(unittest.TestCase):
# line processing # line processing
def test__preprocess_line_removes_leading_dots_after_whitespace(self): def test__preprocess_line_removes_leading_dots_after_whitespace(self):
mon = Monitor() mon = Monitor()
self.assertEqual('help', mon._preprocess_line(' ...help')) self.assertEqual('help', mon._preprocess_line(' ...help'))
@ -17,7 +17,7 @@ class MonitorTests(unittest.TestCase):
def test__preprocess_line_removes_leading_and_trailing_whitespace(self): def test__preprocess_line_removes_leading_and_trailing_whitespace(self):
mon = Monitor() mon = Monitor()
self.assertEqual('help', mon._preprocess_line(' \t help \t ')) self.assertEqual('help', mon._preprocess_line(' \t help \t '))
def test__preprocess_line_rewrites_shortcut_when_alone_on_line(self): def test__preprocess_line_rewrites_shortcut_when_alone_on_line(self):
mon = Monitor() mon = Monitor()
self.assertEqual('assemble', mon._preprocess_line(' a')) self.assertEqual('assemble', mon._preprocess_line(' a'))
@ -32,12 +32,12 @@ class MonitorTests(unittest.TestCase):
def test__preprocess_line_does_not_remove_semicolons_in_quotes(self): def test__preprocess_line_does_not_remove_semicolons_in_quotes(self):
mon = Monitor() mon = Monitor()
self.assertEqual('assemble lda #$";"', self.assertEqual('assemble lda #$";"',
mon._preprocess_line('a lda #$";" ;comment')) mon._preprocess_line('a lda #$";" ;comment'))
def test__preprocess_line_does_not_remove_semicolons_in_apostrophes(self): def test__preprocess_line_does_not_remove_semicolons_in_apostrophes(self):
mon = Monitor() mon = Monitor()
self.assertEqual("assemble lda #$';'", self.assertEqual("assemble lda #$';'",
mon._preprocess_line("assemble lda #$';' ;comment")) mon._preprocess_line("assemble lda #$';' ;comment"))
# add_label # add_label
@ -55,7 +55,7 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_add_label('should be label space value') mon.do_add_label('should be label space value')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("Syntax error: should be label space value\n", out) self.assertEqual("Syntax error: should be label space value\n", out)
def test_do_add_label_adds_label(self): def test_do_add_label_adds_label(self):
stdout = StringIO() stdout = StringIO()
@ -69,7 +69,7 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.help_add_label() mon.help_add_label()
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith("add_label")) self.assertTrue(out.startswith("add_label"))
# assemble # assemble
@ -80,7 +80,7 @@ class MonitorTests(unittest.TestCase):
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('assemble')) self.assertTrue(out.startswith('assemble'))
def test_do_assemble_assembles_valid_statement(self): def test_do_assemble_assembles_valid_statement(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
@ -89,12 +89,12 @@ class MonitorTests(unittest.TestCase):
mpu = mon._mpu mpu = mon._mpu
self.assertEqual(0xA9, mpu.memory[0xC000]) self.assertEqual(0xA9, mpu.memory[0xC000])
self.assertEqual(0xAB, mpu.memory[0xC001]) self.assertEqual(0xAB, mpu.memory[0xC001])
def test_do_assemble_outputs_disassembly(self): def test_do_assemble_outputs_disassembly(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_assemble('c000 lda #$ab') mon.do_assemble('c000 lda #$ab')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("$c000 a9 ab LDA #$ab\n", out) self.assertEqual("$c000 a9 ab LDA #$ab\n", out)
@ -103,7 +103,7 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_add_label('c000 base') mon.do_add_label('c000 base')
mon.do_assemble('c000 rts') mon.do_assemble('c000 rts')
mpu = mon._mpu mpu = mon._mpu
self.assertEqual(0x60, mpu.memory[0xC000]) self.assertEqual(0x60, mpu.memory[0xC000])
@ -111,7 +111,7 @@ class MonitorTests(unittest.TestCase):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_assemble('nonexistant rts') mon.do_assemble('nonexistant rts')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("Bad label: nonexistant\n", out) self.assertEqual("Bad label: nonexistant\n", out)
@ -119,7 +119,7 @@ class MonitorTests(unittest.TestCase):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_assemble('c000 foo') mon.do_assemble('c000 foo')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("Assemble failed: foo\n", out) self.assertEqual("Assemble failed: foo\n", out)
@ -167,13 +167,13 @@ class MonitorTests(unittest.TestCase):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon._address_parser.labels['foo'] = 0xc000 mon._address_parser.labels['foo'] = 0xc000
mon.do_delete_label('foo') mon.do_delete_label('foo')
self.assertFalse(mon._address_parser.labels.has_key('foo')) self.assertFalse(mon._address_parser.labels.has_key('foo'))
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual('', out) self.assertEqual('', out)
# disassemble # disassemble
def test_shortcut_for_disassemble(self): def test_shortcut_for_disassemble(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
@ -211,11 +211,11 @@ class MonitorTests(unittest.TestCase):
self.assertTrue(out.startswith('goto')) self.assertTrue(out.startswith('goto'))
# help # help
def test_help_accepts_command_shortcuts(self): def test_help_accepts_command_shortcuts(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.onecmd("help assemble \t ") mon.onecmd("help assemble \t ")
help_for_command = stdout.getvalue() help_for_command = stdout.getvalue()
@ -234,14 +234,14 @@ class MonitorTests(unittest.TestCase):
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('load')) self.assertTrue(out.startswith('load'))
def test_load_with_more_than_two_args_syntax_error(self): def test_load_with_more_than_two_args_syntax_error(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_load('one two three') mon.do_load('one two three')
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('Syntax error')) self.assertTrue(out.startswith('Syntax error'))
def test_load(self): def test_load(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
@ -249,8 +249,8 @@ class MonitorTests(unittest.TestCase):
filename = tempfile.mktemp() filename = tempfile.mktemp()
try: try:
f = open(filename, 'wb') f = open(filename, 'wb')
f.write(chr(0xAA) + chr(0xBB) + chr(0xCC)) f.write(chr(0xAA) + chr(0xBB) + chr(0xCC))
f.close() f.close()
mon.do_load("'%s' a600" % filename) mon.do_load("'%s' a600" % filename)
self.assertEqual('Wrote +3 bytes from $a600 to $a602\n', self.assertEqual('Wrote +3 bytes from $a600 to $a602\n',
@ -264,10 +264,10 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.help_load() mon.help_load()
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('load')) self.assertTrue(out.startswith('load'))
# mem # mem
def test_shortcut_for_mem(self): def test_shortcut_for_mem(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
@ -275,13 +275,13 @@ class MonitorTests(unittest.TestCase):
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('mem')) self.assertTrue(out.startswith('mem'))
# mpu # mpu
def test_mpu_with_no_args_prints_current_lists_available_mpus(self): def test_mpu_with_no_args_prints_current_lists_available_mpus(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_mpu('') mon.do_mpu('')
lines = stdout.getvalue().splitlines() lines = stdout.getvalue().splitlines()
self.assertEqual(2, len(lines)) self.assertEqual(2, len(lines))
@ -291,7 +291,7 @@ class MonitorTests(unittest.TestCase):
def test_mpu_with_bad_arg_gives_error_lists_available_mpus(self): def test_mpu_with_bad_arg_gives_error_lists_available_mpus(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_mpu('z80') mon.do_mpu('z80')
lines = stdout.getvalue().splitlines() lines = stdout.getvalue().splitlines()
self.assertEqual(2, len(lines)) self.assertEqual(2, len(lines))
@ -301,7 +301,7 @@ class MonitorTests(unittest.TestCase):
def test_mpu_selects_6502(self): def test_mpu_selects_6502(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_mpu('6502') mon.do_mpu('6502')
lines = stdout.getvalue().splitlines() lines = stdout.getvalue().splitlines()
self.assertEqual(1, len(lines)) self.assertEqual(1, len(lines))
@ -311,7 +311,7 @@ class MonitorTests(unittest.TestCase):
def test_mpu_selects_65C02(self): def test_mpu_selects_65C02(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_mpu('65C02') mon.do_mpu('65C02')
lines = stdout.getvalue().splitlines() lines = stdout.getvalue().splitlines()
self.assertEqual(1, len(lines)) self.assertEqual(1, len(lines))
@ -327,27 +327,35 @@ class MonitorTests(unittest.TestCase):
def test_help_mpu(self): def test_help_mpu(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.help_mpu() mon.help_mpu()
lines = stdout.getvalue().splitlines() lines = stdout.getvalue().splitlines()
self.assertEqual("mpu\t\tPrint available microprocessors.", self.assertEqual("mpu\t\tPrint available microprocessors.",
lines[0]) lines[0])
self.assertEqual("mpu <type>\tSelect a new microprocessor.", self.assertEqual("mpu <type>\tSelect a new microprocessor.",
lines[1]) lines[1])
# quit # quit
def test_shortcut_for_quit(self): def test_shortcut_x_for_quit(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_help('x') mon.do_help('x')
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('To quit'))
def test_shortcut_q_for_quit(self):
stdout = StringIO()
mon = Monitor(stdout=stdout)
mon.do_help('q')
out = stdout.getvalue()
self.assertTrue(out.startswith('To quit')) self.assertTrue(out.startswith('To quit'))
def test_do_EOF(self): def test_do_EOF(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
exitnow = mon.do_EOF('') exitnow = mon.do_EOF('')
self.assertEqual(True, exitnow) self.assertEqual(True, exitnow)
@ -360,7 +368,7 @@ class MonitorTests(unittest.TestCase):
def test_do_quit(self): def test_do_quit(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
exitnow = mon.do_quit('') exitnow = mon.do_quit('')
self.assertEqual(True, exitnow) self.assertEqual(True, exitnow)
@ -380,7 +388,7 @@ class MonitorTests(unittest.TestCase):
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("%s\n" % os.getcwd(), out) self.assertEqual("%s\n" % os.getcwd(), out)
def test_help_pwd(self): def test_help_pwd(self):
stdout = StringIO() stdout = StringIO()
@ -408,41 +416,41 @@ class MonitorTests(unittest.TestCase):
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('registers')) self.assertTrue(out.startswith('registers'))
def test_registers_display_returns_to_prompt(self): def test_registers_display_returns_to_prompt(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_registers('') mon.do_registers('')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual('', out) self.assertEqual('', out)
def test_registers_syntax_error_bad_format(self): def test_registers_syntax_error_bad_format(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_registers('x') mon.do_registers('x')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("Syntax error: x\n", out) self.assertEqual("Syntax error: x\n", out)
def test_registers_label_error_bad_value(self): def test_registers_label_error_bad_value(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_registers('x=pony') mon.do_registers('x=pony')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("Label not found: pony\n", out) self.assertEqual("Label not found: pony\n", out)
def test_registers_invalid_register_error(self): def test_registers_invalid_register_error(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_registers('z=3') mon.do_registers('z=3')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("Invalid register: z\n", out) self.assertEqual("Invalid register: z\n", out)
def test_registers_updates_single_register(self): def test_registers_updates_single_register(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_registers('x=42') mon.do_registers('x=42')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("", out) self.assertEqual("", out)
self.assertEqual(0x42, mon._mpu.x) self.assertEqual(0x42, mon._mpu.x)
def test_registers_updates_all_registers(self): def test_registers_updates_all_registers(self):
@ -450,7 +458,7 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_registers('a=42,x=43,y=44,p=45, sp=46, pc=4600') mon.do_registers('a=42,x=43,y=44,p=45, sp=46, pc=4600')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("", out) self.assertEqual("", out)
self.assertEqual(0x42, mon._mpu.a) self.assertEqual(0x42, mon._mpu.a)
self.assertEqual(0x43, mon._mpu.x) self.assertEqual(0x43, mon._mpu.x)
self.assertEqual(0x44, mon._mpu.y) self.assertEqual(0x44, mon._mpu.y)
@ -463,7 +471,7 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.help_registers() mon.help_registers()
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith("registers[<reg_name>")) self.assertTrue(out.startswith("registers[<reg_name>"))
# return # return
@ -476,7 +484,7 @@ class MonitorTests(unittest.TestCase):
self.assertTrue(out.startswith('return')) self.assertTrue(out.startswith('return'))
# reset # reset
def test_do_reset(self): def test_do_reset(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
@ -491,7 +499,7 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.help_reset() mon.help_reset()
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith("reset\t")) self.assertTrue(out.startswith("reset\t"))
# save # save
@ -508,8 +516,8 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_save('filename start') mon.do_save('filename start')
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('Syntax error')) self.assertTrue(out.startswith('Syntax error'))
def test_save(self): def test_save(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
@ -518,7 +526,7 @@ class MonitorTests(unittest.TestCase):
filename = tempfile.mktemp() filename = tempfile.mktemp()
try: try:
mon.do_save("'%s' 0 2" % filename) mon.do_save("'%s' 0 2" % filename)
self.assertEqual('Saved +3 bytes to %s\n' % filename, self.assertEqual('Saved +3 bytes to %s\n' % filename,
stdout.getvalue()) stdout.getvalue())
f = open(filename, 'rb') f = open(filename, 'rb')
@ -534,7 +542,7 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.help_save() mon.help_save()
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith('save')) self.assertTrue(out.startswith('save'))
# step # step
@ -552,7 +560,7 @@ class MonitorTests(unittest.TestCase):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.onecmd('~ $10') mon.onecmd('~ $10')
out = stdout.getvalue() out = stdout.getvalue()
expected = "+16\n$10\n0020\n00010000\n" expected = "+16\n$10\n0020\n00010000\n"
self.assertEqual(expected, out) self.assertEqual(expected, out)
@ -560,15 +568,15 @@ class MonitorTests(unittest.TestCase):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.onecmd('~$10') mon.onecmd('~$10')
out = stdout.getvalue() out = stdout.getvalue()
expected = "+16\n$10\n0020\n00010000\n" expected = "+16\n$10\n0020\n00010000\n"
self.assertEqual(expected, out) self.assertEqual(expected, out)
def test_do_tilde(self): def test_do_tilde(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_tilde('$10') mon.do_tilde('$10')
out = stdout.getvalue() out = stdout.getvalue()
expected = "+16\n$10\n0020\n00010000\n" expected = "+16\n$10\n0020\n00010000\n"
self.assertEqual(expected, out) self.assertEqual(expected, out)
@ -577,8 +585,8 @@ class MonitorTests(unittest.TestCase):
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.help_tilde() mon.help_tilde()
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith("~ <number>")) self.assertTrue(out.startswith("~ <number>"))
# show_labels # show_labels
def test_shortcut_for_show_labels(self): def test_shortcut_for_show_labels(self):
@ -592,26 +600,26 @@ class MonitorTests(unittest.TestCase):
def test_show_labels_displays_labels(self): def test_show_labels_displays_labels(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon._address_parser.labels = {'chrin': 0xffc4, 'chrout': 0xffd2} mon._address_parser.labels = {'chrin': 0xffc4, 'chrout': 0xffd2}
mon.do_show_labels('') mon.do_show_labels('')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("ffc4: chrin\nffd2: chrout\n", out) self.assertEqual("ffc4: chrin\nffd2: chrout\n", out)
def test_help_show_labels(self): def test_help_show_labels(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon._address_parser.labels = {'chrin': 0xffc4, 'chrout': 0xffd2} mon._address_parser.labels = {'chrin': 0xffc4, 'chrout': 0xffd2}
mon.do_show_labels('') mon.do_show_labels('')
out = stdout.getvalue() out = stdout.getvalue()
self.assertEqual("ffc4: chrin\nffd2: chrout\n", out) self.assertEqual("ffc4: chrin\nffd2: chrout\n", out)
# version # version
def test_do_version(self): def test_do_version(self):
stdout = StringIO() stdout = StringIO()
mon = Monitor(stdout=stdout) mon = Monitor(stdout=stdout)
mon.do_version('') mon.do_version('')
out = stdout.getvalue() out = stdout.getvalue()
self.assertTrue(out.startswith("\nPy65")) self.assertTrue(out.startswith("\nPy65"))
def test_help_version(self): def test_help_version(self):