]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/test_symbol_search.vader

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:

Merge commit 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete...
[etc/vim.git] / .vim / bundle / ale / test / test_symbol_search.vader
1 Before:
2   call ale#test#SetDirectory('/testplugin/test')
3   call ale#test#SetFilename('dummy.txt')
4
5   let g:Callback = ''
6   let g:expr_list = []
7   let g:message_list = []
8   let g:preview_called = 0
9   let g:item_list = []
10   let g:options = {}
11   let g:capability_checked = ''
12   let g:conn_id = v:null
13   let g:InitCallback = v:null
14
15   runtime autoload/ale/lsp_linter.vim
16   runtime autoload/ale/lsp.vim
17   runtime autoload/ale/util.vim
18   runtime autoload/ale/preview.vim
19
20   function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
21     let g:conn_id = ale#lsp#Register('executable', '/foo/bar', '', {})
22     call ale#lsp#MarkDocumentAsOpen(g:conn_id, a:buffer)
23     let l:details = {
24     \ 'buffer': a:buffer,
25     \ 'connection_id': g:conn_id,
26     \ 'project_root': '/foo/bar',
27     \ 'language_id': 'python',
28     \}
29
30     let g:InitCallback = {-> a:Callback(a:linter, l:details)}
31   endfunction
32
33   function! ale#lsp#HasCapability(conn_id, capability) abort
34     let g:capability_checked = a:capability
35
36     return 1
37   endfunction
38
39   function! ale#lsp#RegisterCallback(conn_id, callback) abort
40     let g:Callback = a:callback
41   endfunction
42
43   function! ale#lsp#Send(conn_id, message) abort
44     call add(g:message_list, a:message)
45
46     return 42
47   endfunction
48
49   function! ale#util#Execute(expr) abort
50     call add(g:expr_list, a:expr)
51   endfunction
52
53   function! ale#preview#ShowSelection(item_list, options) abort
54     let g:preview_called = 1
55     let g:item_list = a:item_list
56     let g:options = a:options
57   endfunction
58
59 After:
60   call ale#test#RestoreDirectory()
61   call ale#linter#Reset()
62
63   unlet! g:capability_checked
64   unlet! g:InitCallback
65   unlet! g:conn_id
66   unlet! g:Callback
67   unlet! g:message_list
68   unlet! g:expr_list
69   unlet! b:ale_linters
70   unlet! g:options
71   unlet! g:item_list
72   unlet! g:preview_called
73
74   runtime autoload/ale/lsp_linter.vim
75   runtime autoload/ale/lsp.vim
76   runtime autoload/ale/util.vim
77   runtime autoload/ale/preview.vim
78
79 Execute(Other messages for the LSP handler should be ignored):
80   call ale#symbol#HandleLSPResponse(1, {'command': 'foo'})
81
82 Execute(Failed symbol responses should be handled correctly):
83   call ale#symbol#SetMap({3: {}})
84   call ale#symbol#HandleLSPResponse(1, {'id': 3})
85   AssertEqual {}, ale#symbol#GetMap()
86
87 Execute(LSP symbol responses should be handled):
88   call ale#symbol#SetMap({3: {}})
89   call ale#symbol#HandleLSPResponse(
90   \ 1,
91   \ {
92   \   'id': 3,
93   \   'result': [
94   \     {
95   \       'name': 'foo',
96   \       'location': {
97   \         'uri': ale#path#ToFileURI(ale#path#Simplify(g:dir . '/completion_dummy_file')),
98   \         'range': {
99   \           'start': {'line': 2, 'character': 7},
100   \         },
101   \       },
102   \     },
103   \     {
104   \       'name': 'foobar',
105   \       'location': {
106   \         'uri': ale#path#ToFileURI(ale#path#Simplify(g:dir . '/other_file')),
107   \         'range': {
108   \           'start': {'line': 7, 'character': 15},
109   \         },
110   \       },
111   \     },
112   \   ],
113   \ }
114   \)
115
116   AssertEqual
117   \ [
118   \   {
119   \     'filename': ale#path#Simplify(g:dir . '/completion_dummy_file'),
120   \     'line': 3,
121   \     'column': 8,
122   \     'match': 'foo',
123   \   },
124   \   {
125   \     'filename': ale#path#Simplify(g:dir . '/other_file'),
126   \     'line': 8,
127   \     'column': 16,
128   \     'match': 'foobar',
129   \   },
130   \ ],
131   \ g:item_list
132   AssertEqual {}, ale#symbol#GetMap()
133
134 Execute(Preview windows should not be opened for empty LSP symbol responses):
135   call ale#symbol#SetMap({3: {}})
136   call ale#symbol#HandleLSPResponse(
137   \ 1,
138   \ {
139   \   'id': 3,
140   \   'result': [
141   \   ],
142   \ }
143   \)
144
145   Assert !g:preview_called
146   AssertEqual {}, ale#symbol#GetMap()
147   AssertEqual ['echom ''No symbols found.'''], g:expr_list
148
149 Given python(Some Python file):
150   foo
151   somelongerline
152   bazxyzxyzxyz
153
154 Execute(LSP symbol requests should be sent):
155   runtime ale_linters/python/pylsp.vim
156   let b:ale_linters = ['pylsp']
157   call setpos('.', [bufnr(''), 1, 5, 0])
158
159   ALESymbolSearch foo bar
160
161   " We shouldn't register the callback yet.
162   AssertEqual '''''', string(g:Callback)
163
164   AssertEqual type(function('type')), type(g:InitCallback)
165   call g:InitCallback()
166
167   AssertEqual 'symbol_search', g:capability_checked
168   AssertEqual
169   \ 'function(''ale#symbol#HandleLSPResponse'')',
170   \ string(g:Callback)
171
172   AssertEqual
173   \ [
174   \   [0, 'workspace/symbol', {'query': 'foo bar'}],
175   \ ],
176   \ g:message_list
177
178   AssertEqual {'42': {'buffer': bufnr(''), 'use_relative_paths': 0}}, ale#symbol#GetMap()
179
180 Execute('-relative' argument should enable 'use_relative_paths' in HandleLSPResponse):
181   runtime ale_linters/python/pylsp.vim
182   let b:ale_linters = ['pylsp']
183   call setpos('.', [bufnr(''), 1, 5, 0])
184
185   ALESymbolSearch -relative foo bar
186
187   call g:InitCallback()
188
189   AssertEqual {'42': {'buffer': bufnr(''), 'use_relative_paths': 1}}, ale#symbol#GetMap()