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

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / test / test_cursor_warnings.vader
1 Before:
2   Save g:ale_echo_msg_format
3   Save g:ale_echo_cursor
4   Save b:ale_lint_on_insert_leave
5
6   let g:ale_echo_msg_format = '%code: %%s'
7   let b:ale_lint_on_insert_leave = 0
8
9   " We should prefer the error message at column 10 instead of the warning.
10   let g:ale_buffer_info = {
11   \ bufnr('%'): {
12   \   'loclist': [
13   \     {
14   \       'lnum': 1,
15   \       'col': 10,
16   \       'bufnr': bufnr('%'),
17   \       'vcol': 0,
18   \       'linter_name': 'bettercode',
19   \       'nr': -1,
20   \       'type': 'W',
21   \       'code': 'semi',
22   \       'text': 'Ignore me.',
23   \     },
24   \     {
25   \       'lnum': 1,
26   \       'col': 10,
27   \       'bufnr': bufnr('%'),
28   \       'vcol': 0,
29   \       'linter_name': 'bettercode',
30   \       'nr': -1,
31   \       'type': 'E',
32   \       'code': 'semi',
33   \       'text': "Missing semicolon.\r",
34   \       'detail': "Every statement should end with a semicolon\nsecond line",
35   \     },
36   \     {
37   \       'lnum': 1,
38   \       'col': 14,
39   \       'bufnr': bufnr('%'),
40   \       'vcol': 0,
41   \       'linter_name': 'bettercode',
42   \       'nr': -1,
43   \       'type': 'I',
44   \       'text': 'Some information',
45   \     },
46   \     {
47   \       'lnum': 2,
48   \       'col': 10,
49   \       'bufnr': bufnr('%'),
50   \       'vcol': 0,
51   \       'linter_name': 'bettercode',
52   \       'nr': -1,
53   \       'type': 'W',
54   \       'code': 'space-infix-ops',
55   \       'text': 'Infix operators must be spaced.',
56   \     },
57   \     {
58   \       'lnum': 2,
59   \       'col': 15,
60   \       'bufnr': bufnr('%'),
61   \       'vcol': 0,
62   \       'linter_name': 'bettercode',
63   \       'nr': -1,
64   \       'type': 'E',
65   \       'code': 'radix',
66   \       'text': 'Missing radix parameter',
67   \     },
68   \     {
69   \       'lnum': 3,
70   \       'col': 1,
71   \       'bufnr': bufnr('%'),
72   \       'vcol': 0,
73   \       'linter_name': 'bettercode',
74   \       'nr': -1,
75   \       'type': 'E',
76   \       'text': 'lowercase error',
77   \     },
78   \   ],
79   \ },
80   \}
81
82   " Turn off other features, we only care about this one feature in this test.
83   let g:ale_set_loclist = 0
84   let g:ale_set_signs = 0
85   let g:ale_set_highlights = 0
86   let g:ale_echo_cursor = 1
87
88   runtime autoload/ale/cursor.vim
89
90   let g:last_message = ''
91
92   function! ale#cursor#Echom(message) abort
93     let g:last_message = a:message
94   endfunction
95
96   call ale#linter#Reset()
97   call ale#linter#PreventLoading('javascript')
98
99 After:
100   Restore
101
102   unlet! g:last_message
103
104   runtime autoload/ale/cursor.vim
105
106   call cursor(1, 1)
107
108   let g:ale_set_loclist = 1
109   let g:ale_set_signs = 1
110   let g:ale_set_highlights = 1
111
112   let g:ale_buffer_info = {}
113
114   unlet! g:output
115   unlet! b:ale_loclist_msg_format
116
117   " Clearing the messages breaks tests on NeoVim for some reason, but all
118   " we need to do for these tests is just make it so the last message isn't
119   " carried over between test cases.
120   echomsg ''
121
122   " Close the preview window if it's open.
123   if &filetype is# 'ale-preview'
124     noautocmd :q!
125   endif
126
127   call ale#linter#Reset()
128
129 Given javascript(A Javscript file with warnings/errors):
130   var x = 3 + 12345678
131   var x = 5*2 + parseInt("10");
132   //" comment
133
134 Execute(Messages should be shown for the correct lines):
135   call cursor(1, 1)
136   call ale#cursor#EchoCursorWarning()
137
138   AssertEqual 'semi: Missing semicolon.', g:last_message
139
140 Execute(Messages should be shown for earlier columns):
141   call cursor(2, 1)
142   call ale#cursor#EchoCursorWarning()
143
144   AssertEqual 'space-infix-ops: Infix operators must be spaced.', g:last_message
145
146 Execute(Messages should be shown for later columns):
147   call cursor(2, 16)
148   call ale#cursor#EchoCursorWarning()
149
150   AssertEqual 'radix: Missing radix parameter', g:last_message
151
152 Execute(The message at the cursor should be shown when linting ends):
153   call cursor(1, 1)
154   call ale#engine#SetResults(
155   \ bufnr('%'),
156   \ g:ale_buffer_info[bufnr('%')].loclist,
157   \)
158
159   AssertEqual 'semi: Missing semicolon.', g:last_message
160
161 Execute(The message at the cursor should be shown when leaving insert mode):
162   call cursor(2, 9)
163   call feedkeys("i\<Esc>", 'tnix')
164
165   AssertEqual 'space-infix-ops: Infix operators must be spaced.', g:last_message
166
167 Execute(ALEDetail should print 'detail' attributes):
168   call cursor(1, 1)
169
170   ALEDetail
171
172   AssertEqual
173   \ ['Every statement should end with a semicolon', 'second line'],
174   \ getline(1, '$')
175
176 Execute(ALEDetail should print regular 'text' attributes):
177   call cursor(2, 10)
178
179   ALEDetail
180
181   " ALEDetail opens a window, so check the text in it.
182   AssertEqual
183   \ ['Infix operators must be spaced.'],
184   \ getline(1, '$')
185
186 Execute(ALEDetail should not capitlise cursor messages):
187   call cursor(3, 1)
188   call ale#cursor#EchoCursorWarning()
189
190   AssertEqual 'lowercase error', g:last_message
191
192 Execute(The linter name should be formatted into the message correctly):
193   let g:ale_echo_msg_format = '%linter%: %s'
194
195   call cursor(2, 9)
196   call ale#cursor#EchoCursorWarning()
197
198   AssertEqual
199   \ 'bettercode: Infix operators must be spaced.',
200   \ g:last_message
201
202 Execute(The severity should be formatted into the message correctly):
203   let g:ale_echo_msg_format = '%severity%: %s'
204
205   call cursor(2, 9)
206   call ale#cursor#EchoCursorWarning()
207
208   AssertEqual
209   \ 'Warning: Infix operators must be spaced.',
210   \ g:last_message
211
212   call cursor(1, 10)
213   call ale#cursor#EchoCursorWarning()
214
215   AssertEqual 'Error: Missing semicolon.', g:last_message
216
217   call cursor(1, 14)
218   call ale#cursor#EchoCursorWarning()
219
220   AssertEqual 'Info: Some information', g:last_message
221
222 Execute(The type should be formatted into the message correctly):
223   let g:ale_echo_msg_format = '%type%: %s'
224
225   call cursor(2, 9)
226   call ale#cursor#EchoCursorWarning()
227
228   AssertEqual
229   \ 'W: Infix operators must be spaced.',
230   \ g:last_message
231
232   call cursor(1, 10)
233   call ale#cursor#EchoCursorWarning()
234
235   AssertEqual 'E: Missing semicolon.', g:last_message
236
237   call cursor(1, 14)
238   call ale#cursor#EchoCursorWarning()
239
240   AssertEqual 'I: Some information', g:last_message
241
242 Execute(The %code% and %ifcode% should show the code and some text):
243   let g:ale_echo_msg_format = '%(code) %%s'
244
245   call cursor(2, 9)
246   call ale#cursor#EchoCursorWarning()
247
248   AssertEqual
249   \ '(space-infix-ops) Infix operators must be spaced.',
250   \ g:last_message
251
252 Execute(The %code% and %ifcode% should be removed when there's no code):
253   let g:ale_echo_msg_format = '%(code) %%s'
254
255   call cursor(1, 14)
256   call ale#cursor#EchoCursorWarning()
257
258   AssertEqual 'Some information', g:last_message
259
260 Execute(The buffer message format option should take precedence):
261   let g:ale_echo_msg_format = '%(code) %%s'
262   let b:ale_echo_msg_format = 'FOO %s'
263
264   call cursor(1, 14)
265   call ale#cursor#EchoCursorWarning()
266
267   AssertEqual 'FOO Some information', g:last_message
268
269 Execute(The cursor message shouldn't be echoed if the option is off):
270   let g:ale_echo_cursor = 0
271   let g:last_message = 'foo'
272
273   call cursor(1, 1)
274   call ale#cursor#EchoCursorWarning()
275
276   AssertEqual 'foo', g:last_message