Add tests for the completion engine

I tested everything that I thought was interesting enough to warrant a
test: especially the ability to test multiple parameters deep, as well
as testing :set --cycle and some involved example to make sure
completion actually works and updates in realtime
This commit is contained in:
Niklas Haas 2016-08-11 05:15:08 +02:00 committed by Florian Bruhin
parent 26e7ec848f
commit 32cc6bea1d
5 changed files with 122 additions and 16 deletions

View File

@ -1,4 +1,4 @@
Feature: Command bar completion Feature: Using completion
Scenario: No warnings when completing with one entry (#1600) Scenario: No warnings when completing with one entry (#1600)
Given I open about:blank Given I open about:blank
@ -27,3 +27,82 @@ Feature: Command bar completion
Given I open about:blank Given I open about:blank
When I run :set-cmd-text -s :🌀 When I run :set-cmd-text -s :🌀
Then no crash should happen Then no crash should happen
Scenario: Using command completion
When I run :set-cmd-text :
Then the completion model should be CommandCompletionModel
Scenario: Using help completion
When I run :set-cmd-text -s :help
Then the completion model should be HelpCompletionModel
Scenario: Using quickmark completion
When I run :set-cmd-text -s :quickmark-load
Then the completion model should be QuickmarkCompletionModel
Scenario: Using bookmark completion
When I run :set-cmd-text -s :bookmark-load
Then the completion model should be BookmarkCompletionModel
Scenario: Using bind completion
When I run :set-cmd-text -s :bind X
Then the completion model should be BindCompletionModel
Scenario: Using session completion
Given I open data/hello.txt
And I run :session-save hello
When I run :set-cmd-text -s :session-load
And I run :completion-item-focus next
And I run :completion-item-focus next
And I run :session-delete hello
And I run :command-accept
Then the error "Session hello not found!" should be shown
Scenario: Using option completion
When I run :set-cmd-text -s :set colors
Then the completion model should be SettingOptionCompletionModel
Scenario: Using value completion
When I run :set-cmd-text -s :set colors statusbar.bg
Then the completion model should be SettingValueCompletionModel
Scenario: Using value completion multiple times
When I run :set-cmd-text -s :set --cycle colors statusbar.bg black
Then the completion model should be SettingValueCompletionModel
Scenario: Updating the completion in realtime
Given I have a fresh instance
And I set completion -> quick-complete to false
When I open data/hello.txt
And I run :set-cmd-text -s :buffer
And I run :completion-item-focus next
And I open data/hello2.txt in a new background tab
And I run :completion-item-focus next
And I open data/hello3.txt in a new background tab
And I run :completion-item-focus next
And I run :command-accept
Then the following tabs should be open:
- data/hello.txt
- data/hello2.txt
- data/hello3.txt (active)
Scenario: Updating the value completion in realtime
Given I set colors -> statusbar.bg to green
When I run :set-cmd-text -s :set colors statusbar.bg
And I set colors -> statusbar.bg to yellow
And I run :completion-item-focus next
And I run :completion-item-focus next
And I set colors -> statusbar.bg to red
And I run :command-accept
Then colors -> statusbar.bg should be yellow
Scenario: Deleting an open tab via the completion
Given I have a fresh instance
When I open data/hello.txt
And I open data/hello2.txt in a new tab
And I run :set-cmd-text -s :buffer
And I run :completion-item-focus next
And I run :completion-item-focus next
And I run :completion-item-del
Then the following tabs should be open:
- data/hello.txt (active)

View File

@ -181,11 +181,13 @@ def open_path(quteproc, path):
"... as a URL", it's opened according to new-instance-open-target. "... as a URL", it's opened according to new-instance-open-target.
""" """
new_tab = False new_tab = False
new_bg_tab = False
new_window = False new_window = False
as_url = False as_url = False
wait = True wait = True
new_tab_suffix = ' in a new tab' new_tab_suffix = ' in a new tab'
new_bg_tab_suffix = ' in a new background tab'
new_window_suffix = ' in a new window' new_window_suffix = ' in a new window'
do_not_wait_suffix = ' without waiting' do_not_wait_suffix = ' without waiting'
as_url_suffix = ' as a URL' as_url_suffix = ' as a URL'
@ -206,8 +208,22 @@ def open_path(quteproc, path):
else: else:
break break
quteproc.open_path(path, new_tab=new_tab, new_window=new_window, if path.endswith(new_tab_suffix):
as_url=as_url, wait=wait) path = path[:-len(new_tab_suffix)]
new_tab = True
elif path.endswith(new_bg_tab_suffix):
path = path[:-len(new_bg_tab_suffix)]
new_bg_tab = True
elif path.endswith(new_window_suffix):
path = path[:-len(new_window_suffix)]
new_window = True
if path.endswith(do_not_wait_suffix):
path = path[:-len(do_not_wait_suffix)]
wait = False
quteproc.open_path(path, new_tab=new_tab, new_bg_tab=new_bg_tab,
new_window=new_window, as_url=as_url, wait=wait)
@bdd.when(bdd.parsers.parse("I set {sect} -> {opt} to {value}")) @bdd.when(bdd.parsers.parse("I set {sect} -> {opt} to {value}"))
@ -595,3 +611,9 @@ def check_not_scrolled(request, quteproc):
x, y = _get_scroll_values(quteproc) x, y = _get_scroll_values(quteproc)
assert x == 0 assert x == 0
assert y == 0 assert y == 0
@bdd.then(bdd.parsers.parse("{section} -> {option} should be {value}"))
def check_option(quteproc, section, option, value):
actual_value = quteproc.get_setting(section, option)
assert actual_value == value

View File

@ -1,6 +1,6 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2016 Ryan Roden-Corrent (rcorre) <ryan@rcorre.net> # Copyright 2015-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
# #
# This file is part of qutebrowser. # This file is part of qutebrowser.
# #
@ -17,5 +17,13 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import re
import pytest_bdd as bdd import pytest_bdd as bdd
bdd.scenarios('completion.feature') bdd.scenarios('completion.feature')
@bdd.then(bdd.parsers.parse("the completion model should be {model}"))
def check_model(quteproc, model):
"""Make sure the completion model was set to something."""
pattern = "New completion [^:]*: {}".format(model)
quteproc.wait_for(message=re.compile(pattern))

View File

@ -19,9 +19,3 @@
import pytest_bdd as bdd import pytest_bdd as bdd
bdd.scenarios('set.feature') bdd.scenarios('set.feature')
@bdd.then(bdd.parsers.parse("{section} -> {option} should be {value}"))
def check_option(quteproc, section, option, value):
actual_value = quteproc.get_setting(section, option)
assert actual_value == value

View File

@ -475,15 +475,16 @@ class QuteProc(testprocess.Process):
yield yield
self.set_setting(sect, opt, old_value) self.set_setting(sect, opt, old_value)
def open_path(self, path, *, new_tab=False, new_window=False, as_url=False, def open_path(self, path, *, new_tab=False, new_bg_tab=False,
port=None, https=False, wait=True): new_window=False, as_url=False, port=None, https=False,
wait=True):
"""Open the given path on the local webserver in qutebrowser.""" """Open the given path on the local webserver in qutebrowser."""
url = self.path_to_url(path, port=port, https=https) url = self.path_to_url(path, port=port, https=https)
self.open_url(url, new_tab=new_tab, new_window=new_window, self.open_url(url, new_tab=new_tab, new_bg_tab=new_bg_tab,
as_url=as_url, wait=wait) new_window=new_window, wait=wait)
def open_url(self, url, *, new_tab=False, new_window=False, as_url=False, def open_url(self, url, *, new_tab=False, new_bg_tab=False,
wait=True): new_window=False, as_url=False, wait=True):
"""Open the given url in qutebrowser.""" """Open the given url in qutebrowser."""
if new_tab and new_window: if new_tab and new_window:
raise ValueError("new_tab and new_window given!") raise ValueError("new_tab and new_window given!")
@ -492,6 +493,8 @@ class QuteProc(testprocess.Process):
self.send_cmd(url, invalid=True) self.send_cmd(url, invalid=True)
elif new_tab: elif new_tab:
self.send_cmd(':open -t ' + url) self.send_cmd(':open -t ' + url)
elif new_bg_tab:
self.send_cmd(':open -b ' + url)
elif new_window: elif new_window:
self.send_cmd(':open -w ' + url) self.send_cmd(':open -w ' + url)
else: else: