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:
parent
fef1a65247
commit
6573888dc6
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
from qutebrowser.config import configdata, configexc
|
from qutebrowser.config import configdata, configexc
|
||||||
from qutebrowser.completion.models import completionmodel, listcategory, util
|
from qutebrowser.completion.models import completionmodel, listcategory, util
|
||||||
from qutebrowser.commands import runners
|
from qutebrowser.commands import runners, cmdexc
|
||||||
|
|
||||||
|
|
||||||
def option(*, info):
|
def option(*, info):
|
||||||
@ -72,7 +72,11 @@ def bind(key, *, info):
|
|||||||
|
|
||||||
if cmd_text:
|
if cmd_text:
|
||||||
parser = runners.CommandParser()
|
parser = runners.CommandParser()
|
||||||
|
try:
|
||||||
cmd = parser.parse(cmd_text).cmd
|
cmd = parser.parse(cmd_text).cmd
|
||||||
|
except cmdexc.NoSuchCommandError:
|
||||||
|
data = [(cmd_text, 'Invalid command!', key)]
|
||||||
|
else:
|
||||||
data = [(cmd_text, cmd.desc, key)]
|
data = [(cmd_text, cmd.desc, key)]
|
||||||
model.add_category(listcategory.ListCategory("Current", data))
|
model.add_category(listcategory.ListCategory("Current", data))
|
||||||
|
|
||||||
|
@ -119,6 +119,7 @@ def configdata_stub(monkeypatch, configdata_init):
|
|||||||
'normal': collections.OrderedDict([
|
'normal': collections.OrderedDict([
|
||||||
('<ctrl+q>', 'quit'),
|
('<ctrl+q>', 'quit'),
|
||||||
('ZQ', 'quit'),
|
('ZQ', 'quit'),
|
||||||
|
('I', 'invalid'),
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
backends=[],
|
backends=[],
|
||||||
@ -538,7 +539,8 @@ def test_setting_option_completion(qtmodeltester, config_stub,
|
|||||||
"Options": [
|
"Options": [
|
||||||
('aliases', 'Aliases for commands.', '{"q": "quit"}'),
|
('aliases', 'Aliases for commands.', '{"q": "quit"}'),
|
||||||
('bindings.commands', 'Default keybindings',
|
('bindings.commands', 'Default keybindings',
|
||||||
'{"normal": {"<ctrl+q>": "quit", "ZQ": "quit"}}'),
|
'{"normal": {"<ctrl+q>": "quit", "ZQ": "quit", '
|
||||||
|
'"I": "invalid"}}'),
|
||||||
('bindings.default', 'Default keybindings',
|
('bindings.default', 'Default keybindings',
|
||||||
'{"normal": {"<ctrl+q>": "quit"}}'),
|
'{"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,
|
def test_bind_completion_no_current(qtmodeltester, cmdutils_stub, config_stub,
|
||||||
key_config_stub, configdata_stub, info):
|
key_config_stub, configdata_stub, info):
|
||||||
"""Test keybinding completion with no current binding."""
|
"""Test keybinding completion with no current binding."""
|
||||||
|
Loading…
Reference in New Issue
Block a user