2019-05-21 12:53:09 +00:00
|
|
|
import unittest
|
|
|
|
import imp
|
|
|
|
|
|
|
|
ale_module = imp.load_source(
|
|
|
|
'deoplete.sources.ale',
|
|
|
|
'/testplugin/rplugin/python3/deoplete/sources/ale.py',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class VimMock(object):
|
2020-01-01 19:00:41 +00:00
|
|
|
def __init__(self, call_list, call_results, commands):
|
2019-05-21 12:53:09 +00:00
|
|
|
self.__call_list = call_list
|
|
|
|
self.__call_results = call_results
|
|
|
|
|
2020-01-01 19:00:41 +00:00
|
|
|
self.__commands = commands
|
|
|
|
|
2019-05-21 12:53:09 +00:00
|
|
|
def call(self, function, *args):
|
|
|
|
self.__call_list.append((function, args))
|
|
|
|
|
|
|
|
return self.__call_results.get(function, 0)
|
|
|
|
|
2020-01-01 19:00:41 +00:00
|
|
|
def command(self, command):
|
|
|
|
self.__commands.append(command)
|
|
|
|
|
2019-05-21 12:53:09 +00:00
|
|
|
|
|
|
|
class DeopleteSourceTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(DeopleteSourceTest, self).setUp()
|
|
|
|
|
|
|
|
self.call_list = []
|
|
|
|
self.call_results = {'ale#completion#CanProvideCompletions': 1}
|
2020-01-01 19:00:41 +00:00
|
|
|
self.commands = []
|
2019-05-21 12:53:09 +00:00
|
|
|
self.source = ale_module.Source('vim')
|
2020-01-01 19:00:41 +00:00
|
|
|
self.source.vim = VimMock(
|
|
|
|
self.call_list, self.call_results, self.commands)
|
2019-05-21 12:53:09 +00:00
|
|
|
|
|
|
|
def test_attributes(self):
|
|
|
|
"""
|
|
|
|
Check all of the attributes we set.
|
|
|
|
"""
|
|
|
|
attributes = dict(
|
|
|
|
(key, getattr(self.source, key))
|
|
|
|
for key in
|
|
|
|
dir(self.source)
|
|
|
|
if not key.startswith('__')
|
|
|
|
and key != 'vim'
|
|
|
|
and not hasattr(getattr(self.source, key), '__self__')
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertEqual(attributes, {
|
2019-06-25 08:57:38 +00:00
|
|
|
'input_patterns': {
|
|
|
|
'_': r'\.\w*$',
|
|
|
|
'rust': r'(\.|::)\w*$',
|
|
|
|
'typescript': r'(\.|\'|")\w*$',
|
2019-07-14 13:20:44 +00:00
|
|
|
'cpp': r'(\.|::|->)\w*$',
|
2019-06-25 08:57:38 +00:00
|
|
|
},
|
2019-05-21 12:53:09 +00:00
|
|
|
'is_bytepos': True,
|
2020-01-01 19:00:41 +00:00
|
|
|
'is_volatile': True,
|
2019-05-21 12:53:09 +00:00
|
|
|
'mark': '[L]',
|
|
|
|
'min_pattern_length': 1,
|
|
|
|
'name': 'ale',
|
2019-06-15 07:57:11 +00:00
|
|
|
'rank': 1000,
|
2019-05-21 12:53:09 +00:00
|
|
|
})
|
|
|
|
|
2019-06-19 06:25:58 +00:00
|
|
|
def test_complete_position(self):
|
|
|
|
self.call_results['ale#completion#GetCompletionPositionForDeoplete'] = 2
|
|
|
|
context = {'input': 'foo'}
|
2019-05-21 12:53:09 +00:00
|
|
|
|
2019-06-19 06:25:58 +00:00
|
|
|
self.assertEqual(self.source.get_complete_position(context), 2)
|
2019-05-21 12:53:09 +00:00
|
|
|
self.assertEqual(self.call_list, [
|
2019-06-19 06:25:58 +00:00
|
|
|
('ale#completion#GetCompletionPositionForDeoplete', ('foo',)),
|
2019-05-21 12:53:09 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
def test_request_completion_results(self):
|
2020-01-01 19:00:41 +00:00
|
|
|
context = {'event': 'TextChangedI', 'is_refresh': True}
|
2019-05-21 12:53:09 +00:00
|
|
|
|
|
|
|
self.assertEqual(self.source.gather_candidates(context), [])
|
|
|
|
self.assertEqual(self.call_list, [
|
|
|
|
('ale#completion#CanProvideCompletions', ()),
|
2020-01-01 19:00:41 +00:00
|
|
|
])
|
|
|
|
self.assertEqual(self.commands, [
|
|
|
|
"call ale#completion#GetCompletions('ale-callback', " + \
|
|
|
|
"{'callback': {completions -> deoplete#auto_complete() }})"
|
2019-05-21 12:53:09 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
def test_request_completion_results_from_buffer_without_providers(self):
|
|
|
|
self.call_results['ale#completion#CanProvideCompletions'] = 0
|
2020-01-01 19:00:41 +00:00
|
|
|
context = {'event': 'TextChangedI', 'is_refresh': True}
|
2019-05-21 12:53:09 +00:00
|
|
|
|
|
|
|
self.assertIsNone(self.source.gather_candidates(context), [])
|
|
|
|
self.assertEqual(self.call_list, [
|
|
|
|
('ale#completion#CanProvideCompletions', ()),
|
|
|
|
])
|
|
|
|
|
2020-01-01 19:00:41 +00:00
|
|
|
def test_async_event(self):
|
|
|
|
context = {'event': 'Async', 'is_refresh': True}
|
2019-05-21 12:53:09 +00:00
|
|
|
self.call_results['ale#completion#GetCompletionResult'] = [
|
|
|
|
{
|
|
|
|
'word': 'foobar',
|
|
|
|
'kind': 'v',
|
|
|
|
'icase': 1,
|
|
|
|
'menu': '',
|
|
|
|
'info': '',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
self.assertEqual(self.source.gather_candidates(context), [
|
|
|
|
{
|
|
|
|
'word': 'foobar',
|
|
|
|
'kind': 'v',
|
|
|
|
'icase': 1,
|
|
|
|
'menu': '',
|
|
|
|
'info': '',
|
|
|
|
},
|
|
|
|
])
|
2020-01-01 19:00:41 +00:00
|
|
|
|
2019-05-21 12:53:09 +00:00
|
|
|
self.assertEqual(self.call_list, [
|
|
|
|
('ale#completion#CanProvideCompletions', ()),
|
|
|
|
('ale#completion#GetCompletionResult', ()),
|
|
|
|
])
|