1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
"""
Adapted from a code editor component created
for Enki editor as replacement for QScintilla.
Copyright (C) 2020 Andrei Kopats
Originally licensed under the terms of GNU Lesser General Public License
as published by the Free Software Foundation, version 2.1 of the license.
This is compatible with Orange3's GPL-3.0 license.
""" # pylint: disable=duplicate-code
import unittest
from Orange.widgets.data.utils.pythoneditor.brackethighlighter import BracketHighlighter
from Orange.widgets.data.utils.pythoneditor.tests.base import EditorTest
class Test(EditorTest):
def _verify(self, actual, expected):
converted = []
for item in actual:
if item.format.foreground().color() == BracketHighlighter.MATCHED_COLOR:
matched = True
elif item.format.foreground().color() == BracketHighlighter.UNMATCHED_COLOR:
matched = False
else:
self.fail("Invalid color")
start = item.cursor.selectionStart()
end = item.cursor.selectionEnd()
converted.append((start, end, matched))
self.assertEqual(converted, expected)
def test_1(self):
self.qpart.lines = \
['func(param,',
' "text ( param"))']
firstBlock = self.qpart.document().firstBlock()
secondBlock = firstBlock.next()
bh = BracketHighlighter()
self._verify(bh.extraSelections(self.qpart, firstBlock, 1),
[])
self._verify(bh.extraSelections(self.qpart, firstBlock, 4),
[(4, 5, True), (31, 32, True)])
self._verify(bh.extraSelections(self.qpart, firstBlock, 5),
[(4, 5, True), (31, 32, True)])
self._verify(bh.extraSelections(self.qpart, secondBlock, 11),
[])
self._verify(bh.extraSelections(self.qpart, secondBlock, 19),
[(31, 32, True), (4, 5, True)])
self._verify(bh.extraSelections(self.qpart, secondBlock, 20),
[(32, 33, False)])
self._verify(bh.extraSelections(self.qpart, secondBlock, 21),
[(32, 33, False)])
if __name__ == '__main__':
unittest.main()
|