]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/python/test_deoplete_source.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / test / python / test_deoplete_source.py
1 import unittest
2 import imp
3
4 ale_module = imp.load_source(
5     'deoplete.sources.ale',
6     '/testplugin/rplugin/python3/deoplete/sources/ale.py',
7 )
8
9
10 class VimMock(object):
11     def __init__(self, call_list, call_results, commands):
12         self.__call_list = call_list
13         self.__call_results = call_results
14
15         self.__commands = commands
16
17     def call(self, function, *args):
18         self.__call_list.append((function, args))
19
20         return self.__call_results.get(function, 0)
21
22     def command(self, command):
23         self.__commands.append(command)
24
25
26 class DeopleteSourceTest(unittest.TestCase):
27     def setUp(self):
28         super(DeopleteSourceTest, self).setUp()
29
30         self.call_list = []
31         self.call_results = {'ale#completion#CanProvideCompletions': 1}
32         self.commands = []
33         self.source = ale_module.Source('vim')
34         self.source.vim = VimMock(
35             self.call_list, self.call_results, self.commands)
36
37     def test_attributes(self):
38         """
39         Check all of the attributes we set.
40         """
41         attributes = dict(
42             (key, getattr(self.source, key))
43             for key in
44             dir(self.source)
45             if not key.startswith('__')
46             and key != 'vim'
47             and not hasattr(getattr(self.source, key), '__self__')
48         )
49
50         self.assertEqual(attributes, {
51             'input_patterns': {
52                 '_': r'\.\w*$',
53                 'rust': r'(\.|::)\w*$',
54                 'typescript': r'(\.|\'|")\w*$',
55                 'cpp': r'(\.|::|->)\w*$',
56                 'c': r'(\.|->)\w*$',
57             },
58             'is_bytepos': True,
59             'is_volatile': True,
60             'mark': '[L]',
61             'min_pattern_length': 1,
62             'name': 'ale',
63             'rank': 1000,
64         })
65
66     def test_complete_position(self):
67         self.call_results['ale#completion#GetCompletionPositionForDeoplete'] = 2
68         context = {'input': 'foo'}
69
70         self.assertEqual(self.source.get_complete_position(context), 2)
71         self.assertEqual(self.call_list, [
72             ('ale#completion#GetCompletionPositionForDeoplete', ('foo',)),
73         ])
74
75     def test_request_completion_results(self):
76         context = {'event': 'TextChangedI', 'is_refresh': True}
77
78         self.assertEqual(self.source.gather_candidates(context), [])
79         self.assertEqual(self.call_list, [
80             ('ale#completion#CanProvideCompletions', ()),
81         ])
82         self.assertEqual(self.commands, [
83             "call ale#completion#GetCompletions('ale-callback', " + \
84             "{'callback': {completions -> deoplete#auto_complete() }})"
85         ])
86
87     def test_request_completion_results_from_buffer_without_providers(self):
88         self.call_results['ale#completion#CanProvideCompletions'] = 0
89         context = {'event': 'TextChangedI', 'is_refresh': True}
90
91         self.assertIsNone(self.source.gather_candidates(context), [])
92         self.assertEqual(self.call_list, [
93             ('ale#completion#CanProvideCompletions', ()),
94         ])
95
96     def test_async_event(self):
97         context = {'event': 'Async', 'is_refresh': True}
98         self.call_results['ale#completion#GetCompletionResult'] = [
99             {
100                 'word': 'foobar',
101                 'kind': 'v',
102                 'icase': 1,
103                 'menu': '',
104                 'info': '',
105             },
106         ]
107
108         self.assertEqual(self.source.gather_candidates(context), [
109             {
110                 'word': 'foobar',
111                 'kind': 'v',
112                 'icase': 1,
113                 'menu': '',
114                 'info': '',
115             },
116         ])
117
118         self.assertEqual(self.call_list, [
119             ('ale#completion#CanProvideCompletions', ()),
120             ('ale#completion#GetCompletionResult', ()),
121         ])