Fix :bind completion with invalid commands

Now that Command doesn't validate things anymore, we can't rely on parsing to
work.
This commit is contained in:
Florian Bruhin 2017-09-27 11:10:25 +02:00
parent fef1a65247
commit 6573888dc6
2 changed files with 29 additions and 4 deletions

View File

@ -21,7 +21,7 @@
from qutebrowser.config import configdata, configexc
from qutebrowser.completion.models import completionmodel, listcategory, util
from qutebrowser.commands import runners
from qutebrowser.commands import runners, cmdexc
def option(*, info):
@ -72,8 +72,12 @@ def bind(key, *, info):
if cmd_text:
parser = runners.CommandParser()
cmd = parser.parse(cmd_text).cmd
data = [(cmd_text, cmd.desc, key)]
try:
cmd = parser.parse(cmd_text).cmd
except cmdexc.NoSuchCommandError:
data = [(cmd_text, 'Invalid command!', key)]
else:
data = [(cmd_text, cmd.desc, key)]
model.add_category(listcategory.ListCategory("Current", data))
cmdlist = util.get_cmd_completions(info, include_hidden=True,

View File

@ -119,6 +119,7 @@ def configdata_stub(monkeypatch, configdata_init):
'normal': collections.OrderedDict([
('<ctrl+q>', 'quit'),
('ZQ', 'quit'),
('I', 'invalid'),
])
},
backends=[],
@ -538,7 +539,8 @@ def test_setting_option_completion(qtmodeltester, config_stub,
"Options": [
('aliases', 'Aliases for commands.', '{"q": "quit"}'),
('bindings.commands', 'Default keybindings',
'{"normal": {"<ctrl+q>": "quit", "ZQ": "quit"}}'),
'{"normal": {"<ctrl+q>": "quit", "ZQ": "quit", '
'"I": "invalid"}}'),
('bindings.default', 'Default keybindings',
'{"normal": {"<ctrl+q>": "quit"}}'),
]
@ -573,6 +575,25 @@ def test_bind_completion(qtmodeltester, cmdutils_stub, config_stub,
})
def test_bind_completion_invalid(cmdutils_stub, config_stub, key_config_stub,
configdata_stub, info):
"""Test command completion with an invalid command bound."""
model = configmodel.bind('I', info=info)
model.set_pattern('')
_check_completions(model, {
"Current": [
('invalid', 'Invalid command!', 'I'),
],
"Commands": [
('open', 'open a url', ''),
('q', "Alias for 'quit'", ''),
('quit', 'quit qutebrowser', 'ZQ, <ctrl+q>'),
('scroll', 'Scroll the current tab in the given direction.', '')
],
})
def test_bind_completion_no_current(qtmodeltester, cmdutils_stub, config_stub,
key_config_stub, configdata_stub, info):
"""Test keybinding completion with no current binding."""