mirror of
https://github.com/mnaberez/py65.git
synced 2024-11-18 15:06:35 +00:00
Command shortcuts now work when the command has no args.
This commit is contained in:
parent
ab7c84659a
commit
87de997a78
@ -68,28 +68,30 @@ class Monitor(cmd.Cmd):
|
||||
'z': 'step'}
|
||||
|
||||
def _preprocess_line(self, line):
|
||||
# ignore leading dots
|
||||
line = line.lstrip('.')
|
||||
# line comments
|
||||
quoted = False
|
||||
for pos, char in enumerate(line):
|
||||
if char in ('"', "'"):
|
||||
quoted = not quoted
|
||||
if (not quoted) and (char == ';'):
|
||||
line = line[:pos]
|
||||
break
|
||||
|
||||
# whitepsace & leading dots
|
||||
line = line.strip(' \t').lstrip('.')
|
||||
|
||||
# command shortcuts
|
||||
for shortcut, command in self._shortcuts.iteritems():
|
||||
if line == shortcut:
|
||||
line = command
|
||||
break
|
||||
|
||||
pattern = '^%s\s+' % re.escape(shortcut)
|
||||
matches = re.match(pattern, line)
|
||||
if matches:
|
||||
start, end = matches.span()
|
||||
line = "%s %s" % (command, line[end:])
|
||||
|
||||
# line comments
|
||||
quoted = False
|
||||
for pos in range(0, len(line)):
|
||||
if line[pos] in ('"', "'"):
|
||||
quoted = not quoted
|
||||
if (not quoted) and (line[pos] == ';'):
|
||||
line = line[:pos]
|
||||
break
|
||||
|
||||
if line == 'a':
|
||||
line = 'assemble'
|
||||
|
||||
return line
|
||||
|
||||
|
@ -9,13 +9,35 @@ class MonitorTests(unittest.TestCase):
|
||||
|
||||
# line processing
|
||||
|
||||
def test_preprocess_line_removes_leading_dots(self):
|
||||
stdout = StringIO()
|
||||
mon = Monitor(stdout=stdout)
|
||||
mon.onecmd('...help')
|
||||
|
||||
out = stdout.getvalue()
|
||||
self.assert_('Documented commands' in out)
|
||||
def test__preprocess_line_removes_leading_dots_after_whitespace(self):
|
||||
mon = Monitor()
|
||||
self.assertEqual('help', mon._preprocess_line(' ...help'))
|
||||
|
||||
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'))
|
||||
|
||||
def test__preprocess_line_rewrites_shortcut_with_arguments_on_line(self):
|
||||
mon = Monitor()
|
||||
self.assertEqual('assemble c000', mon._preprocess_line('a c000'))
|
||||
|
||||
def test__preprocess_line_removes_semicolon_comments(self):
|
||||
mon = Monitor()
|
||||
self.assertEqual('assemble', mon._preprocess_line('a ;comment'))
|
||||
|
||||
def test__preprocess_line_does_not_remove_semicolons_in_quotes(self):
|
||||
mon = Monitor()
|
||||
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 #$';'",
|
||||
mon._preprocess_line("assemble lda #$';' ;comment"))
|
||||
|
||||
# assemble
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user