]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/test/lsp/omni.vimspec

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 / vim-lsp / test / lsp / omni.vimspec
1 Describe lsp#omni
2
3     let g:lsp_get_vim_completion_item_set_kind = 1
4
5     Before each
6         call lsp#omni#_clear_managed_user_data_map()
7     End
8
9     Describe lsp#omni#get_vim_completion_items
10         It should return item with proper kind
11             let item = {
12             \ 'label': 'my-label',
13             \ 'documentation': 'my documentation.',
14             \ 'detail': 'my-detail',
15             \ 'kind': '3'
16             \}
17
18             let options = {
19             \ 'server': { 'name': 'dummy-server' },
20             \ 'position': lsp#get_position(),
21             \ 'response': { 'result': [item] },
22             \}
23
24             let want = {
25             \ 'items': [{
26             \   'word': 'my-label',
27             \   'abbr': 'my-label',
28             \   'icase': 1,
29             \   'dup': 1,
30             \   'empty': 1,
31             \   'kind': 'function',
32             \   'user_data': '{"vim-lsp/key":"0"}',
33             \ }],
34             \ 'incomplete': 0,
35             \ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
36             \}
37
38             Assert Equals(lsp#omni#get_vim_completion_items(options), want)
39         End
40
41         It should get user_data by the item
42             if !has('patch-8.0.1493')
43                 Skip This test requires 'patch-8.0.1493'
44             endif
45
46             let item = {
47             \ 'label': 'my-label',
48             \ 'documentation': 'my documentation.',
49             \ 'detail': 'my-detail',
50             \ 'kind': '3',
51             \ 'textEdit': {
52             \    'range': {
53             \      'start': {'line': 5, 'character': 0},
54             \      'end': {'line': 5, 'character': 5}
55             \    },
56             \    'newText': 'yyy'
57             \  }
58             \}
59
60             let options = {
61             \ 'server': { 'name': 'dummy-server' },
62             \ 'position': { 'line': 1, 'character': 1 },
63             \ 'response': { 'result': [item] },
64             \}
65
66             let want = {
67             \ 'items': [{
68             \  'word': 'yyy',
69             \  'abbr': 'my-label',
70             \  'icase': 1,
71             \  'dup': 1,
72             \  'empty': 1,
73             \  'kind': 'function',
74             \  'user_data': '{"vim-lsp/key":"0"}',
75             \  }],
76             \  'incomplete': 0,
77             \  'startcol': lsp#utils#position#lsp_character_to_vim('%', {'line': 1, 'character': 0}),
78             \}
79
80             let got = lsp#omni#get_vim_completion_items(options)
81             Assert Equals(got, want)
82             Assert Equals(lsp#omni#get_managed_user_data_from_completed_item(got['items'][0]), {
83                         \   'server_name': 'dummy-server',
84                         \   'completion_item': item,
85                         \   'complete_position': { 'line': 1, 'character': 1 },
86                         \   'start_character': 0,
87                         \   'complete_word': 'yyy',
88                         \ })
89         End
90
91         It should not raise errors
92             let item = {
93             \ 'label': 'my-label',
94             \ 'textEdit': v:null,
95             \}
96
97             let options = {
98             \ 'server': { 'name': 'dummy-server' },
99             \ 'position': lsp#get_position(),
100             \ 'response': { 'result': [item] },
101             \}
102
103             let want = {
104             \ 'items': [{
105             \  'word': 'my-label',
106             \  'abbr': 'my-label',
107             \  'icase': 1,
108             \  'dup': 1,
109             \  'empty': 1,
110             \  'kind': '',
111             \  'user_data': '{"vim-lsp/key":"0"}',
112             \  }],
113             \  'incomplete': 0,
114             \  'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
115             \}
116
117             let got = lsp#omni#get_vim_completion_items(options)
118             Assert Equals(got, want)
119
120             let item = {
121             \ 'label': 'my-label',
122             \ 'textEdit': v:null,
123             \ 'insertText': v:null,
124             \}
125
126             let options = {
127             \ 'server': { 'name': 'dummy-server' },
128             \ 'position': lsp#get_position(),
129             \ 'response': { 'result': [item] },
130             \}
131
132             let want = {
133             \ 'items': [{
134             \  'word': 'my-label',
135             \  'abbr': 'my-label',
136             \  'icase': 1,
137             \  'dup': 1,
138             \  'empty': 1,
139             \  'kind': '',
140             \  'user_data': '{"vim-lsp/key":"1"}',
141             \  }],
142             \  'incomplete': 0,
143             \  'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
144             \}
145
146             let got = lsp#omni#get_vim_completion_items(options)
147             Assert Equals(got, want)
148         End
149
150         It should return correct items for snippets
151             if !has('patch-8.0.1493')
152                 Skip This test requires 'patch-8.0.1493'
153             endif
154
155             let item = {
156                 \ "label": "sysout",
157                 \ "insertText": "System.out.println(${0});",
158                 \ "kind": 15,
159                 \ "insertTextFormat": 2,
160                 \ "documentation": "System.out.println();",
161                 \ "detail": "print to standard out"
162                 \ }
163
164             let options = {
165             \ 'server': { 'name': 'dummy-server' },
166             \ 'position': { 'line': 1, 'character': 1 },
167             \ 'response': { 'result': [item] },
168             \}
169
170             let want = {
171             \ 'items': [{
172             \  'word': 'System.out.println',
173             \  'abbr': 'sysout~',
174             \  'icase': 1,
175             \  'dup': 1,
176             \  'empty': 1,
177             \  'kind': 'snippet',
178             \  'user_data': '{"vim-lsp/key":"0"}',
179             \  }],
180             \  'incomplete': 0,
181             \  'startcol': lsp#utils#position#lsp_character_to_vim('%', { 'line': 1, 'character': 1 }),
182             \}
183
184             let got = lsp#omni#get_vim_completion_items(options)
185             Assert Equals(got, want)
186             Assert Equals(lsp#omni#get_managed_user_data_from_completed_item(got['items'][0]), {
187                         \   'server_name': 'dummy-server',
188                         \   'completion_item': item,
189                         \   'complete_position': { 'line': 1, 'character': 1 },
190                         \   'start_character': 0,
191                         \   'complete_word': 'System.out.println(${0});',
192                         \ })
193         End
194
195         It should sort by sortText
196             let items = [{
197             \ 'label': 'my-label1',
198             \ 'kind': '3',
199             \ 'sortText': 'c'
200             \},
201             \{
202             \ 'label': 'my-label2',
203             \ 'kind': '3',
204             \ 'sortText': 'a'
205             \},
206             \{
207             \ 'label': 'my-label3',
208             \ 'kind': '3',
209             \ 'sortText': 'b'
210             \}]
211
212             let options = {
213             \ 'server': {
214             \   'name': 'dummy-server',
215             \   'config': {
216             \     'sort': { 'max': 100 },
217             \   },
218             \  },
219             \ 'position': lsp#get_position(),
220             \ 'response': { 'result': items },
221             \}
222
223             let want = {
224             \ 'items': [{
225             \   'word': 'my-label2',
226             \   'abbr': 'my-label2',
227             \   'icase': 1,
228             \   'dup': 1,
229             \   'empty': 1,
230             \   'kind': 'function',
231             \   'user_data': '{"vim-lsp/key":"0"}',
232             \ },
233             \ {
234             \   'word': 'my-label3',
235             \   'abbr': 'my-label3',
236             \   'icase': 1,
237             \   'dup': 1,
238             \   'empty': 1,
239             \   'kind': 'function',
240             \   'user_data': '{"vim-lsp/key":"1"}',
241             \ },
242             \ {
243             \   'word': 'my-label1',
244             \   'abbr': 'my-label1',
245             \   'icase': 1,
246             \   'dup': 1,
247             \   'empty': 1,
248             \   'kind': 'function',
249             \   'user_data': '{"vim-lsp/key":"2"}',
250             \ }],
251             \ 'incomplete': 0,
252             \ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
253             \}
254
255             Assert Equals(lsp#omni#get_vim_completion_items(options), want)
256         End
257
258         It should not sort over max
259             let items = [{
260             \ 'label': 'my-label3',
261             \ 'kind': '3',
262             \ 'sortText': '3'
263             \},
264             \{
265             \ 'label': 'my-label1',
266             \ 'kind': '3',
267             \ 'sortText': '1'
268             \},
269             \{
270             \ 'label': 'my-label2',
271             \ 'kind': '3',
272             \ 'sortText': '2'
273             \}]
274
275             let options = {
276             \ 'server': {
277             \   'name': 'dummy-server',
278             \   'config': {
279             \     'sort': { 'max': 2 },
280             \   },
281             \  },
282             \ 'position': lsp#get_position(),
283             \ 'response': { 'result': items },
284             \}
285
286             let want = {
287             \ 'items': [{
288             \   'word': 'my-label3',
289             \   'abbr': 'my-label3',
290             \   'icase': 1,
291             \   'dup': 1,
292             \   'empty': 1,
293             \   'kind': 'function',
294             \   'user_data': '{"vim-lsp/key":"0"}',
295             \ },
296             \ {
297             \   'word': 'my-label1',
298             \   'abbr': 'my-label1',
299             \   'icase': 1,
300             \   'dup': 1,
301             \   'empty': 1,
302             \   'kind': 'function',
303             \   'user_data': '{"vim-lsp/key":"1"}',
304             \ },
305             \ {
306             \   'word': 'my-label2',
307             \   'abbr': 'my-label2',
308             \   'icase': 1,
309             \   'dup': 1,
310             \   'empty': 1,
311             \   'kind': 'function',
312             \   'user_data': '{"vim-lsp/key":"2"}',
313             \ }],
314             \ 'incomplete': 0,
315             \ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
316             \}
317             Assert Equals(lsp#omni#get_vim_completion_items(options), want)
318         End
319
320         It should sort by label(sortText not exists)
321             let items = [{
322             \ 'label': 'my-label3',
323             \ 'kind': '3',
324             \},
325             \{
326             \ 'label': 'my-label1',
327             \ 'kind': '3',
328             \},
329             \{
330             \ 'label': 'my-label2',
331             \ 'kind': '3',
332             \}]
333
334             let options = {
335             \ 'server': {
336             \   'name': 'dummy-server',
337             \   'config': {
338             \     'sort': { 'max': 10 },
339             \   },
340             \  },
341             \ 'position': lsp#get_position(),
342             \ 'response': { 'result': items },
343             \}
344
345             let want = {
346             \ 'items': [{
347             \   'word': 'my-label1',
348             \   'abbr': 'my-label1',
349             \   'icase': 1,
350             \   'dup': 1,
351             \   'empty': 1,
352             \   'kind': 'function',
353             \   'user_data': '{"vim-lsp/key":"0"}',
354             \ },
355             \ {
356             \   'word': 'my-label2',
357             \   'abbr': 'my-label2',
358             \   'icase': 1,
359             \   'dup': 1,
360             \   'empty': 1,
361             \   'kind': 'function',
362             \   'user_data': '{"vim-lsp/key":"1"}',
363             \ },
364             \ {
365             \   'word': 'my-label3',
366             \   'abbr': 'my-label3',
367             \   'icase': 1,
368             \   'dup': 1,
369             \   'empty': 1,
370             \   'kind': 'function',
371             \   'user_data': '{"vim-lsp/key":"2"}',
372             \ }],
373             \ 'incomplete': 0,
374             \ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
375             \}
376             Assert Equals(lsp#omni#get_vim_completion_items(options), want)
377         End
378
379         It should sort by label(empty sortText)
380             let items = [{
381             \ 'label': 'my-label3',
382             \ 'kind': '3',
383             \ 'sortText': ''
384             \},
385             \{
386             \ 'label': 'my-label1',
387             \ 'kind': '3',
388             \ 'sortText': '',
389             \},
390             \{
391             \ 'label': 'my-label2',
392             \ 'kind': '3',
393             \ 'sortText': '',
394             \}]
395
396             let options = {
397             \ 'server': {
398             \   'name': 'dummy-server',
399             \   'config': {
400             \     'sort': { 'max': 10 },
401             \   },
402             \  },
403             \ 'position': lsp#get_position(),
404             \ 'response': { 'result': items },
405             \}
406
407             let want = {
408             \ 'items': [{
409             \   'word': 'my-label1',
410             \   'abbr': 'my-label1',
411             \   'icase': 1,
412             \   'dup': 1,
413             \   'empty': 1,
414             \   'kind': 'function',
415             \   'user_data': '{"vim-lsp/key":"0"}',
416             \ },
417             \ {
418             \   'word': 'my-label2',
419             \   'abbr': 'my-label2',
420             \   'icase': 1,
421             \   'dup': 1,
422             \   'empty': 1,
423             \   'kind': 'function',
424             \   'user_data': '{"vim-lsp/key":"1"}',
425             \ },
426             \ {
427             \   'word': 'my-label3',
428             \   'abbr': 'my-label3',
429             \   'icase': 1,
430             \   'dup': 1,
431             \   'empty': 1,
432             \   'kind': 'function',
433             \   'user_data': '{"vim-lsp/key":"2"}',
434             \ }],
435             \ 'incomplete': 0,
436             \ 'startcol': lsp#utils#position#lsp_character_to_vim('%', lsp#get_position()),
437             \}
438             Assert Equals(lsp#omni#get_vim_completion_items(options), want)
439         End
440
441         Describe g:lsp_ignorecase
442             Before all
443                 let saved_ignorecase = get(g:, 'lsp_ignorecase', v:null)
444             End
445
446             After all
447                 if saved_ignorecase isnot v:null
448                     let g:lsp_ignorecase = saved_ignorecase
449                 endif
450             End
451
452             It should sort completion items case-insensitive when true is set
453                 let g:lsp_ignorecase = v:true
454
455                 " 'B' < 'a' but 'a' < 'b'
456                 let result = [{
457                 \ 'label': 'my-label1',
458                 \ 'kind': '3',
459                 \ 'sortText': 'B'
460                 \},
461                 \{
462                 \ 'label': 'my-label2',
463                 \ 'kind': '3',
464                 \ 'sortText': 'a'
465                 \}]
466
467                 let options = {
468                 \ 'server': {
469                 \   'name': 'dummy-server',
470                 \   'config': {
471                 \     'sort': { 'max': 10 },
472                 \   },
473                 \ },
474                 \ 'position': lsp#get_position(),
475                 \ 'response': { 'result': result },
476                 \}
477
478                 let want = [{
479                 \  'word': 'my-label2',
480                 \  'abbr': 'my-label2',
481                 \  'icase': 1,
482                 \  'dup': 1,
483                 \  'empty': 1,
484                 \  'kind': 'function',
485                 \  'user_data': '{"vim-lsp/key":"0"}',
486                 \},
487                 \{
488                 \  'word': 'my-label1',
489                 \  'abbr': 'my-label1',
490                 \  'icase': 1,
491                 \  'dup': 1,
492                 \  'empty': 1,
493                 \  'kind': 'function',
494                 \  'user_data': '{"vim-lsp/key":"1"}',
495                 \}]
496
497                 Assert Equals(lsp#omni#get_vim_completion_items(options).items, want)
498             End
499         End
500     End
501 End