2018-09-15 18:37:34 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
|
|
# Copyright 2018 Ryan Roden-Corrent (rcorre) <ryan@rcorre.net>
|
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
import pytest
|
2018-09-22 17:58:35 +02:00
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
from PyQt5.QtGui import QTextDocument
|
2018-09-15 18:37:34 +02:00
|
|
|
|
|
|
|
from qutebrowser.completion import completiondelegate
|
|
|
|
|
|
|
|
|
2018-09-22 17:58:35 +02:00
|
|
|
@pytest.mark.parametrize('pat,txt,segments', [
|
|
|
|
('foo', 'foo', [(0, 3)]),
|
|
|
|
('foo', 'foobar', [(0, 3)]),
|
2018-10-06 09:57:01 +02:00
|
|
|
('foo', 'FOObar', [(0, 3)]), # re.IGNORECASE
|
2018-09-22 17:58:35 +02:00
|
|
|
('foo', 'barfoo', [(3, 3)]),
|
|
|
|
('foo', 'barfoobaz', [(3, 3)]),
|
|
|
|
('foo', 'barfoobazfoo', [(3, 3), (9, 3)]),
|
|
|
|
('foo', 'foofoo', [(0, 3), (3, 3)]),
|
|
|
|
('a|b', 'cadb', [(1, 1), (3, 1)]),
|
|
|
|
('foo', '<foo>', [(1, 3)]),
|
|
|
|
('<a>', "<a>bc", [(0, 3)]),
|
2018-09-15 19:35:32 +02:00
|
|
|
|
|
|
|
# https://github.com/qutebrowser/qutebrowser/issues/4199
|
2018-09-22 17:58:35 +02:00
|
|
|
('foo', "'foo'", [(1, 3)]),
|
|
|
|
('x', "'x'", [(1, 1)]),
|
|
|
|
('lt', "<lt", [(1, 2)]),
|
2018-09-15 18:37:34 +02:00
|
|
|
])
|
2018-09-22 17:58:35 +02:00
|
|
|
def test_highlight(pat, txt, segments):
|
|
|
|
doc = QTextDocument(txt)
|
|
|
|
highlighter = completiondelegate._Highlighter(doc, pat, Qt.red)
|
|
|
|
highlighter.setFormat = mock.Mock()
|
|
|
|
highlighter.highlightBlock(txt)
|
|
|
|
highlighter.setFormat.assert_has_calls([
|
|
|
|
mock.call(s[0], s[1], mock.ANY) for s in segments
|
|
|
|
])
|