mirror of
https://github.com/mnaberez/py65.git
synced 2024-12-29 06:29:48 +00:00
Add "q" as a shortcut for "quit"
This commit is contained in:
parent
7b48d3e794
commit
b55d045eff
@ -127,6 +127,7 @@ class Monitor(cmd.Cmd):
|
||||
'g': 'goto',
|
||||
'l': 'load',
|
||||
'm': 'mem',
|
||||
'q': 'quit',
|
||||
'r': 'registers',
|
||||
'ret': 'return',
|
||||
'rad': 'radix',
|
||||
|
@ -9,7 +9,7 @@ from StringIO import StringIO
|
||||
class MonitorTests(unittest.TestCase):
|
||||
|
||||
# line processing
|
||||
|
||||
|
||||
def test__preprocess_line_removes_leading_dots_after_whitespace(self):
|
||||
mon = Monitor()
|
||||
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):
|
||||
mon = Monitor()
|
||||
self.assertEqual('help', mon._preprocess_line(' \t help \t '))
|
||||
|
||||
|
||||
def test__preprocess_line_rewrites_shortcut_when_alone_on_line(self):
|
||||
mon = Monitor()
|
||||
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):
|
||||
mon = Monitor()
|
||||
self.assertEqual('assemble lda #$";"',
|
||||
self.assertEqual('assemble lda #$";"',
|
||||
mon._preprocess_line('a lda #$";" ;comment'))
|
||||
|
||||
def test__preprocess_line_does_not_remove_semicolons_in_apostrophes(self):
|
||||
mon = Monitor()
|
||||
self.assertEqual("assemble lda #$';'",
|
||||
self.assertEqual("assemble lda #$';'",
|
||||
mon._preprocess_line("assemble lda #$';' ;comment"))
|
||||
|
||||
# add_label
|
||||
@ -55,7 +55,7 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_add_label('should be label space value')
|
||||
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):
|
||||
stdout = StringIO()
|
||||
@ -69,7 +69,7 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.help_add_label()
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith("add_label"))
|
||||
self.assertTrue(out.startswith("add_label"))
|
||||
|
||||
# assemble
|
||||
|
||||
@ -80,7 +80,7 @@ class MonitorTests(unittest.TestCase):
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith('assemble'))
|
||||
|
||||
|
||||
def test_do_assemble_assembles_valid_statement(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
@ -89,12 +89,12 @@ class MonitorTests(unittest.TestCase):
|
||||
mpu = mon._mpu
|
||||
self.assertEqual(0xA9, mpu.memory[0xC000])
|
||||
self.assertEqual(0xAB, mpu.memory[0xC001])
|
||||
|
||||
|
||||
def test_do_assemble_outputs_disassembly(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_assemble('c000 lda #$ab')
|
||||
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual("$c000 a9 ab LDA #$ab\n", out)
|
||||
|
||||
@ -103,7 +103,7 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_add_label('c000 base')
|
||||
mon.do_assemble('c000 rts')
|
||||
|
||||
|
||||
mpu = mon._mpu
|
||||
self.assertEqual(0x60, mpu.memory[0xC000])
|
||||
|
||||
@ -111,7 +111,7 @@ class MonitorTests(unittest.TestCase):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_assemble('nonexistant rts')
|
||||
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual("Bad label: nonexistant\n", out)
|
||||
|
||||
@ -119,7 +119,7 @@ class MonitorTests(unittest.TestCase):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_assemble('c000 foo')
|
||||
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual("Assemble failed: foo\n", out)
|
||||
|
||||
@ -167,13 +167,13 @@ class MonitorTests(unittest.TestCase):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
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'))
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual('', out)
|
||||
|
||||
# disassemble
|
||||
|
||||
|
||||
def test_shortcut_for_disassemble(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
@ -211,11 +211,11 @@ class MonitorTests(unittest.TestCase):
|
||||
self.assertTrue(out.startswith('goto'))
|
||||
|
||||
# help
|
||||
|
||||
|
||||
def test_help_accepts_command_shortcuts(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
|
||||
|
||||
mon.onecmd("help assemble \t ")
|
||||
help_for_command = stdout.getvalue()
|
||||
|
||||
@ -234,14 +234,14 @@ class MonitorTests(unittest.TestCase):
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith('load'))
|
||||
|
||||
|
||||
def test_load_with_more_than_two_args_syntax_error(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_load('one two three')
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith('Syntax error'))
|
||||
|
||||
self.assertTrue(out.startswith('Syntax error'))
|
||||
|
||||
def test_load(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
@ -249,8 +249,8 @@ class MonitorTests(unittest.TestCase):
|
||||
filename = tempfile.mktemp()
|
||||
try:
|
||||
f = open(filename, 'wb')
|
||||
f.write(chr(0xAA) + chr(0xBB) + chr(0xCC))
|
||||
f.close()
|
||||
f.write(chr(0xAA) + chr(0xBB) + chr(0xCC))
|
||||
f.close()
|
||||
|
||||
mon.do_load("'%s' a600" % filename)
|
||||
self.assertEqual('Wrote +3 bytes from $a600 to $a602\n',
|
||||
@ -264,10 +264,10 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.help_load()
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith('load'))
|
||||
self.assertTrue(out.startswith('load'))
|
||||
|
||||
# mem
|
||||
|
||||
|
||||
def test_shortcut_for_mem(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
@ -275,13 +275,13 @@ class MonitorTests(unittest.TestCase):
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith('mem'))
|
||||
|
||||
|
||||
# mpu
|
||||
|
||||
def test_mpu_with_no_args_prints_current_lists_available_mpus(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_mpu('')
|
||||
mon.do_mpu('')
|
||||
|
||||
lines = stdout.getvalue().splitlines()
|
||||
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):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_mpu('z80')
|
||||
mon.do_mpu('z80')
|
||||
|
||||
lines = stdout.getvalue().splitlines()
|
||||
self.assertEqual(2, len(lines))
|
||||
@ -301,7 +301,7 @@ class MonitorTests(unittest.TestCase):
|
||||
def test_mpu_selects_6502(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_mpu('6502')
|
||||
mon.do_mpu('6502')
|
||||
|
||||
lines = stdout.getvalue().splitlines()
|
||||
self.assertEqual(1, len(lines))
|
||||
@ -311,7 +311,7 @@ class MonitorTests(unittest.TestCase):
|
||||
def test_mpu_selects_65C02(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_mpu('65C02')
|
||||
mon.do_mpu('65C02')
|
||||
|
||||
lines = stdout.getvalue().splitlines()
|
||||
self.assertEqual(1, len(lines))
|
||||
@ -327,27 +327,35 @@ class MonitorTests(unittest.TestCase):
|
||||
def test_help_mpu(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.help_mpu()
|
||||
|
||||
lines = stdout.getvalue().splitlines()
|
||||
self.assertEqual("mpu\t\tPrint available microprocessors.",
|
||||
mon.help_mpu()
|
||||
|
||||
lines = stdout.getvalue().splitlines()
|
||||
self.assertEqual("mpu\t\tPrint available microprocessors.",
|
||||
lines[0])
|
||||
self.assertEqual("mpu <type>\tSelect a new microprocessor.",
|
||||
lines[1])
|
||||
lines[1])
|
||||
|
||||
# quit
|
||||
|
||||
def test_shortcut_for_quit(self):
|
||||
def test_shortcut_x_for_quit(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
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'))
|
||||
|
||||
def test_do_EOF(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon = Monitor(stdout=stdout)
|
||||
exitnow = mon.do_EOF('')
|
||||
self.assertEqual(True, exitnow)
|
||||
|
||||
@ -360,7 +368,7 @@ class MonitorTests(unittest.TestCase):
|
||||
|
||||
def test_do_quit(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon = Monitor(stdout=stdout)
|
||||
exitnow = mon.do_quit('')
|
||||
self.assertEqual(True, exitnow)
|
||||
|
||||
@ -380,7 +388,7 @@ class MonitorTests(unittest.TestCase):
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual("%s\n" % os.getcwd(), out)
|
||||
|
||||
|
||||
|
||||
def test_help_pwd(self):
|
||||
stdout = StringIO()
|
||||
@ -408,41 +416,41 @@ class MonitorTests(unittest.TestCase):
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith('registers'))
|
||||
|
||||
|
||||
def test_registers_display_returns_to_prompt(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_registers('')
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual('', out)
|
||||
|
||||
self.assertEqual('', out)
|
||||
|
||||
def test_registers_syntax_error_bad_format(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_registers('x')
|
||||
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):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_registers('x=pony')
|
||||
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):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_registers('z=3')
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual("Invalid register: z\n", out)
|
||||
self.assertEqual("Invalid register: z\n", out)
|
||||
|
||||
def test_registers_updates_single_register(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_registers('x=42')
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual("", out)
|
||||
self.assertEqual("", out)
|
||||
self.assertEqual(0x42, mon._mpu.x)
|
||||
|
||||
def test_registers_updates_all_registers(self):
|
||||
@ -450,7 +458,7 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_registers('a=42,x=43,y=44,p=45, sp=46, pc=4600')
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual("", out)
|
||||
self.assertEqual("", out)
|
||||
self.assertEqual(0x42, mon._mpu.a)
|
||||
self.assertEqual(0x43, mon._mpu.x)
|
||||
self.assertEqual(0x44, mon._mpu.y)
|
||||
@ -463,7 +471,7 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.help_registers()
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith("registers[<reg_name>"))
|
||||
self.assertTrue(out.startswith("registers[<reg_name>"))
|
||||
|
||||
# return
|
||||
|
||||
@ -476,7 +484,7 @@ class MonitorTests(unittest.TestCase):
|
||||
self.assertTrue(out.startswith('return'))
|
||||
|
||||
# reset
|
||||
|
||||
|
||||
def test_do_reset(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
@ -491,7 +499,7 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.help_reset()
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith("reset\t"))
|
||||
self.assertTrue(out.startswith("reset\t"))
|
||||
|
||||
# save
|
||||
|
||||
@ -508,8 +516,8 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_save('filename start')
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith('Syntax error'))
|
||||
|
||||
self.assertTrue(out.startswith('Syntax error'))
|
||||
|
||||
def test_save(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
@ -518,7 +526,7 @@ class MonitorTests(unittest.TestCase):
|
||||
filename = tempfile.mktemp()
|
||||
try:
|
||||
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())
|
||||
|
||||
f = open(filename, 'rb')
|
||||
@ -534,7 +542,7 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.help_save()
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith('save'))
|
||||
self.assertTrue(out.startswith('save'))
|
||||
|
||||
# step
|
||||
|
||||
@ -552,7 +560,7 @@ class MonitorTests(unittest.TestCase):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.onecmd('~ $10')
|
||||
out = stdout.getvalue()
|
||||
out = stdout.getvalue()
|
||||
expected = "+16\n$10\n0020\n00010000\n"
|
||||
self.assertEqual(expected, out)
|
||||
|
||||
@ -560,15 +568,15 @@ class MonitorTests(unittest.TestCase):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.onecmd('~$10')
|
||||
out = stdout.getvalue()
|
||||
out = stdout.getvalue()
|
||||
expected = "+16\n$10\n0020\n00010000\n"
|
||||
self.assertEqual(expected, out)
|
||||
|
||||
|
||||
def test_do_tilde(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_tilde('$10')
|
||||
out = stdout.getvalue()
|
||||
out = stdout.getvalue()
|
||||
expected = "+16\n$10\n0020\n00010000\n"
|
||||
self.assertEqual(expected, out)
|
||||
|
||||
@ -577,8 +585,8 @@ class MonitorTests(unittest.TestCase):
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.help_tilde()
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith("~ <number>"))
|
||||
|
||||
self.assertTrue(out.startswith("~ <number>"))
|
||||
|
||||
# show_labels
|
||||
|
||||
def test_shortcut_for_show_labels(self):
|
||||
@ -592,26 +600,26 @@ class MonitorTests(unittest.TestCase):
|
||||
def test_show_labels_displays_labels(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon._address_parser.labels = {'chrin': 0xffc4, 'chrout': 0xffd2}
|
||||
mon._address_parser.labels = {'chrin': 0xffc4, 'chrout': 0xffd2}
|
||||
mon.do_show_labels('')
|
||||
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):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon._address_parser.labels = {'chrin': 0xffc4, 'chrout': 0xffd2}
|
||||
mon._address_parser.labels = {'chrin': 0xffc4, 'chrout': 0xffd2}
|
||||
mon.do_show_labels('')
|
||||
out = stdout.getvalue()
|
||||
self.assertEqual("ffc4: chrin\nffd2: chrout\n", out)
|
||||
self.assertEqual("ffc4: chrin\nffd2: chrout\n", out)
|
||||
|
||||
# version
|
||||
|
||||
|
||||
def test_do_version(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.do_version('')
|
||||
out = stdout.getvalue()
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(out.startswith("\nPy65"))
|
||||
|
||||
def test_help_version(self):
|
||||
|
Loading…
Reference in New Issue
Block a user