]> git.madduck.net Git - etc/vim.git/blob - test/sign/test_sign_placement.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / test / sign / test_sign_placement.vader
1 Before:
2   Save g:ale_buffer_info
3   Save g:ale_echo_cursor
4   Save g:ale_run_synchronously
5   Save g:ale_set_highlights
6   Save g:ale_set_loclist
7   Save g:ale_set_quickfix
8   Save g:ale_set_signs
9   Save g:ale_command_wrapper
10
11   let g:ale_command_wrapper = ''
12   let g:ale_buffer_info = {}
13   let g:ale_run_synchronously = 1
14   let g:ale_set_signs = 1
15   " Disable features we don't need for these tests.
16   let g:ale_set_quickfix = 0
17   let g:ale_set_loclist = 0
18   let g:ale_set_highlights = 0
19   let g:ale_echo_cursor = 0
20
21   call ale#linter#Reset()
22   call ale#sign#Clear()
23
24   function! GenerateResults(buffer, output)
25     return [
26     \ {
27     \   'lnum': 1,
28     \   'col': 1,
29     \   'type': 'E',
30     \   'text': 'foo',
31     \ },
32     \ {
33     \   'lnum': 2,
34     \   'col': 1,
35     \   'type': 'W',
36     \   'text': 'bar',
37     \ },
38     \ {
39     \   'lnum': 3,
40     \   'col': 1,
41     \   'type': 'E',
42     \   'text': 'baz',
43     \ },
44     \ {
45     \   'lnum': 4,
46     \   'col': 1,
47     \   'type': 'E',
48     \   'text': 'use this one',
49     \ },
50     \ {
51     \   'lnum': 4,
52     \   'col': 2,
53     \   'type': 'W',
54     \   'text': 'ignore this one',
55     \ },
56     \ {
57     \   'lnum': 5,
58     \   'col': 1,
59     \   'type': 'W',
60     \   'text': 'ignore this one',
61     \ },
62     \ {
63     \   'lnum': 5,
64     \   'col': 2,
65     \   'type': 'E',
66     \   'text': 'use this one',
67     \ },
68     \]
69   endfunction
70
71   function! ParseSigns()
72     redir => l:output
73       if has('nvim-0.4.2') || has('patch-8.1.614')
74         silent sign place group=ale_signs
75       else
76         silent sign place
77       endif
78     redir END
79
80     return map(
81     \ split(l:output, '\n')[2:],
82     \ 'matchlist(v:val, ''' . ale#sign#ParsePattern() . ''')[1:3]',
83     \)
84   endfunction
85
86   call ale#linter#Define('testft', {
87   \ 'name': 'x',
88   \ 'executable': has('win32') ? 'cmd' : 'true',
89   \ 'command': 'true',
90   \ 'callback': 'GenerateResults',
91   \})
92
93 After:
94   Restore
95
96   unlet! g:ale_run_synchronously_callbacks
97   unlet! g:loclist
98   delfunction GenerateResults
99   delfunction ParseSigns
100   call ale#linter#Reset()
101   call ale#sign#Clear()
102
103 Execute(ale#sign#GetSignName should return the right sign names):
104   AssertEqual 'ALEErrorSign', ale#sign#GetSignName([{'type': 'E'}])
105   AssertEqual 'ALEStyleErrorSign', ale#sign#GetSignName([{'type': 'E', 'sub_type': 'style'}])
106   AssertEqual 'ALEWarningSign', ale#sign#GetSignName([{'type': 'W'}])
107   AssertEqual 'ALEStyleWarningSign', ale#sign#GetSignName([{'type': 'W', 'sub_type': 'style'}])
108   AssertEqual 'ALEInfoSign', ale#sign#GetSignName([{'type': 'I'}])
109   AssertEqual 'ALEErrorSign', ale#sign#GetSignName([
110   \ {'type': 'E'},
111   \ {'type': 'W'},
112   \ {'type': 'I'},
113   \ {'type': 'E', 'sub_type': 'style'},
114   \ {'type': 'W', 'sub_type': 'style'},
115   \])
116   AssertEqual 'ALEWarningSign', ale#sign#GetSignName([
117   \ {'type': 'W'},
118   \ {'type': 'I'},
119   \ {'type': 'E', 'sub_type': 'style'},
120   \ {'type': 'W', 'sub_type': 'style'},
121   \])
122   AssertEqual 'ALEInfoSign', ale#sign#GetSignName([
123   \ {'type': 'I'},
124   \ {'type': 'E', 'sub_type': 'style'},
125   \ {'type': 'W', 'sub_type': 'style'},
126   \])
127   AssertEqual 'ALEStyleErrorSign', ale#sign#GetSignName([
128   \ {'type': 'E', 'sub_type': 'style'},
129   \ {'type': 'W', 'sub_type': 'style'},
130   \])
131   AssertEqual 'ALEStyleWarningSign', ale#sign#GetSignName([
132   \ {'type': 'W', 'sub_type': 'style'},
133   \])
134
135 Given testft(A file with warnings/errors):
136   Foo
137   Bar
138   Baz
139   Fourth line
140   Fifth line
141
142 Execute(The current signs should be set for running a job):
143   ALELint
144   call ale#test#FlushJobs()
145
146   AssertEqual
147   \ [
148   \   ['1', '1000001', 'ALEErrorSign'],
149   \   ['2', '1000002', 'ALEWarningSign'],
150   \   ['3', '1000003', 'ALEErrorSign'],
151   \   ['4', '1000004', 'ALEErrorSign'],
152   \   ['5', '1000005', 'ALEErrorSign'],
153   \ ],
154   \ ParseSigns()
155
156 Execute(Loclist items with sign_id values should be kept):
157   if has('nvim-0.4.2') || has('patch-8.1.614')
158     exec 'sign place 1000347 group=ale_signs line=3 name=ALEErrorSign buffer=' . bufnr('')
159     exec 'sign place 1000348 group=ale_signs line=15 name=ALEErrorSign buffer=' . bufnr('')
160     exec 'sign place 1000349 group=ale_signs line=16 name=ALEWarningSign buffer=' . bufnr('')
161   else
162     exec 'sign place 1000347 line=3 name=ALEErrorSign buffer=' . bufnr('')
163     exec 'sign place 1000348 line=15 name=ALEErrorSign buffer=' . bufnr('')
164     exec 'sign place 1000349 line=16 name=ALEWarningSign buffer=' . bufnr('')
165   endif
166
167   let g:loclist = [
168   \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a', 'sign_id': 1000348},
169   \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 1, 'type': 'W', 'text': 'b', 'sign_id': 1000349},
170   \ {'bufnr': bufnr(''), 'lnum': 3, 'col': 1, 'type': 'E', 'text': 'c', 'sign_id': 1000347},
171   \ {'bufnr': bufnr(''), 'lnum': 4, 'col': 1, 'type': 'W', 'text': 'd'},
172   \ {'bufnr': bufnr(''), 'lnum': 15, 'col': 2, 'type': 'W', 'text': 'e'},
173   \ {'bufnr': bufnr(''), 'lnum': 16, 'col': 2, 'type': 'E', 'text': 'f'},
174   \]
175
176   call ale#sign#SetSigns(bufnr(''), g:loclist)
177
178   " Sign IDs from before should be kept, and new signs should use
179   " IDs that haven't been used yet.
180   AssertEqual
181   \ [
182   \   {'bufnr': bufnr(''), 'lnum': 3, 'col': 1, 'type': 'E', 'text': 'c', 'sign_id': 1000347},
183   \   {'bufnr': bufnr(''), 'lnum': 4, 'col': 1, 'type': 'W', 'text': 'd', 'sign_id': 1000350},
184   \   {'bufnr': bufnr(''), 'lnum': 15, 'col': 1, 'type': 'E', 'text': 'a', 'sign_id': 1000348},
185   \   {'bufnr': bufnr(''), 'lnum': 15, 'col': 2, 'type': 'W', 'text': 'e', 'sign_id': 1000348},
186   \   {'bufnr': bufnr(''), 'lnum': 16, 'col': 1, 'type': 'W', 'text': 'b', 'sign_id': 1000351},
187   \   {'bufnr': bufnr(''), 'lnum': 16, 'col': 2, 'type': 'E', 'text': 'f', 'sign_id': 1000351},
188   \ ],
189   \ g:loclist
190
191   " Items should be grouped again. We should see error signs, where there
192   " were warnings before, and errors where there were errors and where we
193   " now have new warnings.
194   AssertEqual
195   \ [
196   \   ['15', '1000348', 'ALEErrorSign'],
197   \   ['16', '1000351', 'ALEErrorSign'],
198   \   ['3', '1000347', 'ALEErrorSign'],
199   \   ['4', '1000350', 'ALEWarningSign'],
200   \ ],
201   \ sort(ParseSigns())
202
203 Execute(Items for other buffers should be ignored):
204   let g:loclist = [
205   \ {'bufnr': bufnr('') - 1, 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a'},
206   \ {'bufnr': bufnr('') - 1, 'lnum': 2, 'col': 1, 'type': 'E', 'text': 'a', 'sign_id': 1000347},
207   \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a'},
208   \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 1, 'type': 'W', 'text': 'b'},
209   \ {'bufnr': bufnr(''), 'lnum': 3, 'col': 1, 'type': 'E', 'text': 'c'},
210   \ {'bufnr': bufnr(''), 'lnum': 4, 'col': 1, 'type': 'W', 'text': 'd'},
211   \ {'bufnr': bufnr(''), 'lnum': 15, 'col': 2, 'type': 'W', 'text': 'e'},
212   \ {'bufnr': bufnr(''), 'lnum': 16, 'col': 2, 'type': 'E', 'text': 'f'},
213   \ {'bufnr': bufnr('') + 1, 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a'},
214   \]
215
216   call ale#sign#SetSigns(bufnr(''), g:loclist)
217
218   AssertEqual
219   \ [
220   \   ['1', '1000001', 'ALEErrorSign'],
221   \   ['15', '1000005', 'ALEWarningSign'],
222   \   ['16', '1000006', 'ALEErrorSign'],
223   \   ['2', '1000002', 'ALEWarningSign'],
224   \   ['3', '1000003', 'ALEErrorSign'],
225   \   ['4', '1000004', 'ALEWarningSign'],
226   \ ],
227   \ sort(ParseSigns())
228
229 Execute(Signs should be downgraded correctly):
230   call ale#sign#SetSigns(bufnr(''), [
231   \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'x'},
232   \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 1, 'type': 'W', 'text': 'x'},
233   \])
234
235   AssertEqual
236   \ [
237   \   ['1', '1000001', 'ALEErrorSign'],
238   \   ['2', '1000002', 'ALEWarningSign'],
239   \ ],
240   \ sort(ParseSigns())
241
242   call ale#sign#SetSigns(bufnr(''), [
243   \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'W', 'text': 'x'},
244   \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 1, 'type': 'I', 'text': 'x'},
245   \])
246
247   AssertEqual
248   \ [
249   \   ['1', '1000003', 'ALEWarningSign'],
250   \   ['2', '1000004', 'ALEInfoSign'],
251   \ ],
252   \ sort(ParseSigns())
253
254 Execute(Signs should be upgraded correctly):
255   call ale#sign#SetSigns(bufnr(''), [
256   \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'W', 'text': 'x'},
257   \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 1, 'type': 'I', 'text': 'x'},
258   \])
259
260   AssertEqual
261   \ [
262   \   ['1', '1000001', 'ALEWarningSign'],
263   \   ['2', '1000002', 'ALEInfoSign'],
264   \ ],
265   \ sort(ParseSigns())
266
267   call ale#sign#SetSigns(bufnr(''), [
268   \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'x'},
269   \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 1, 'type': 'W', 'text': 'x'},
270   \])
271
272   AssertEqual
273   \ [
274   \   ['1', '1000003', 'ALEErrorSign'],
275   \   ['2', '1000004', 'ALEWarningSign'],
276   \ ],
277   \ sort(ParseSigns())
278
279 Execute(It should be possible to clear signs with empty lists):
280   " We can fail to remove signs if there are multiple signs on one line,
281   " say after deleting lines in Vim, etc.
282   if has('nvim-0.4.2') || has('patch-8.1.614')
283     exec 'sign place 1000347 group=ale_signs line=3 name=ALEErrorSign buffer=' . bufnr('')
284     exec 'sign place 1000348 group=ale_signs line=3 name=ALEWarningSign buffer=' . bufnr('')
285     exec 'sign place 1000349 group=ale_signs line=10 name=ALEErrorSign buffer=' . bufnr('')
286     exec 'sign place 1000350 group=ale_signs line=10 name=ALEWarningSign buffer=' . bufnr('')
287   else
288     exec 'sign place 1000347 line=3 name=ALEErrorSign buffer=' . bufnr('')
289     exec 'sign place 1000348 line=3 name=ALEWarningSign buffer=' . bufnr('')
290     exec 'sign place 1000349 line=10 name=ALEErrorSign buffer=' . bufnr('')
291     exec 'sign place 1000350 line=10 name=ALEWarningSign buffer=' . bufnr('')
292   endif
293
294   call ale#sign#SetSigns(bufnr(''), [])
295   AssertEqual [], ParseSigns()
296
297 Execute(No exceptions should be thrown when setting signs for invalid buffers):
298   call ale#sign#SetSigns(123456789, [{'lnum': 15, 'col': 2, 'type': 'W', 'text': 'e'}])