]> git.madduck.net Git - etc/vim.git/blob - test/test_loclist_corrections.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 / test_loclist_corrections.vader
1 Before:
2   Save g:ale_filename_mappings
3
4   let g:ale_filename_mappings = {}
5
6 After:
7   unlet! b:temp_name
8   unlet! b:other_bufnr
9
10   Restore
11
12
13 Execute(FixLocList should map filenames):
14   " Paths converted back into temporary filenames shouldn't be included.
15   let g:ale_filename_mappings = {
16   \ 'linter2': [['/xxx/', '/data/']],
17   \ 'linter1': [
18   \   ['/bar/', '/data/special/'],
19   \   ['/foo/', '/data/'],
20   \   [
21   \     ale#path#Simplify(fnamemodify(ale#util#Tempname(), ':h:h')) . '/',
22   \     '/x-tmp/',
23   \   ],
24   \ ],
25   \}
26
27   AssertEqual
28   \ [
29   \   '/foo/file.txt',
30   \   v:null,
31   \   '/bar/file.txt',
32   \ ],
33   \ map(
34   \   ale#engine#FixLocList(
35   \     bufnr('%'),
36   \     'linter1',
37   \     0,
38   \     [
39   \       {'text': 'x', 'lnum': 1, 'filename': '/data/file.txt'},
40   \       {'text': 'x', 'lnum': 1, 'filename': '/x-tmp/file.txt'},
41   \       {'text': 'x', 'lnum': 1, 'filename': '/data/special/file.txt'},
42   \     ],
43   \   ),
44   \   'get(v:val, ''filename'', v:null)',
45   \ )
46
47
48 Given foo (Some file with lines to count):
49   foo12345678
50   bar12345678
51   baz12345678
52   four12345678
53   five12345678
54   six12345678
55   seven12345678
56   eight12345678
57   nine12345678
58   ten12345678
59
60 Execute(FixLocList should set all the default values correctly):
61   AssertEqual
62   \ [
63   \   {
64   \     'text': 'a',
65   \     'lnum': 2,
66   \     'col': 0,
67   \     'bufnr': bufnr('%'),
68   \     'vcol': 0,
69   \     'type': 'E',
70   \     'nr': -1,
71   \     'linter_name': 'foobar',
72   \   },
73   \   {
74   \     'text': 'b',
75   \     'lnum': 2,
76   \     'col': 0,
77   \     'bufnr': bufnr('%'),
78   \     'vcol': 0,
79   \     'type': 'E',
80   \     'nr': -1,
81   \     'linter_name': 'foobar',
82   \   },
83   \ ],
84   \ ale#engine#FixLocList(
85   \   bufnr('%'),
86   \   'foobar',
87   \   0,
88   \   [{'text': 'a', 'lnum': 2}, {'text': 'b', 'lnum': 2}],
89   \ )
90
91 Execute(FixLocList should use the values we supply):
92   AssertEqual
93   \ [
94   \   {
95   \     'text': 'a',
96   \     'lnum': 3,
97   \     'col': 4,
98   \     'bufnr': 10000,
99   \     'vcol': 0,
100   \     'type': 'W',
101   \     'nr': 42,
102   \     'linter_name': 'foobar',
103   \   },
104   \ ],
105   \ ale#engine#FixLocList(
106   \   bufnr('%'),
107   \   'foobar',
108   \   0,
109   \   [{
110   \     'text': 'a',
111   \     'lnum': 3,
112   \     'col': 4,
113   \     'bufnr': 10000,
114   \     'vcol': 1,
115   \     'type': 'W',
116   \     'nr': 42,
117   \   }],
118   \ )
119
120 Execute(FixLocList should set items with lines beyond the end to the last line):
121   AssertEqual
122   \ [
123   \   {
124   \     'text': 'a',
125   \     'lnum': 10,
126   \     'col': 0,
127   \     'end_lnum': 10,
128   \     'bufnr': bufnr('%'),
129   \     'vcol': 0,
130   \     'type': 'E',
131   \     'nr': -1,
132   \     'linter_name': 'foobar',
133   \   },
134   \ ],
135   \ ale#engine#FixLocList(
136   \   bufnr('%'),
137   \   'foobar',
138   \   0,
139   \   [{'text': 'a', 'lnum': 11, 'end_lnum': 12}],
140   \ )
141
142 Execute(FixLocList should move line 0 to line 1):
143   AssertEqual
144   \ [
145   \   {
146   \     'text': 'a',
147   \     'lnum': 1,
148   \     'col': 0,
149   \     'bufnr': bufnr('%'),
150   \     'vcol': 0,
151   \     'type': 'E',
152   \     'nr': -1,
153   \     'linter_name': 'foobar',
154   \   },
155   \ ],
156   \ ale#engine#FixLocList(
157   \   bufnr('%'),
158   \   'foobar',
159   \   0,
160   \   [{'text': 'a', 'lnum': 0}],
161   \ )
162
163 Execute(FixLocList should convert line and column numbers correctly):
164   " The numbers should be 10, not 8 as octals.
165   AssertEqual
166   \ [
167   \   {
168   \     'text': 'a',
169   \     'lnum': 10,
170   \     'col': 10,
171   \     'bufnr': bufnr('%'),
172   \     'vcol': 0,
173   \     'type': 'E',
174   \     'nr': -1,
175   \     'linter_name': 'foobar',
176   \   },
177   \ ],
178   \ ale#engine#FixLocList(
179   \   bufnr('%'),
180   \   'foobar',
181   \   0,
182   \   [{'text': 'a', 'lnum': '010', 'col': '010'}],
183   \ )
184
185 Execute(FixLocList should pass on end_col values):
186   " The numbers should be 10, not 8 as octals.
187   AssertEqual
188   \ [
189   \   {
190   \     'text': 'a',
191   \     'lnum': 10,
192   \     'col': 10,
193   \     'end_col': 12,
194   \     'bufnr': bufnr('%'),
195   \     'vcol': 0,
196   \     'type': 'E',
197   \     'nr': -1,
198   \     'linter_name': 'foobar',
199   \   },
200   \   {
201   \     'text': 'a',
202   \     'lnum': 10,
203   \     'col': 11,
204   \     'end_col': 12,
205   \     'bufnr': bufnr('%'),
206   \     'vcol': 0,
207   \     'type': 'E',
208   \     'nr': -1,
209   \     'linter_name': 'foobar',
210   \   },
211   \ ],
212   \ ale#engine#FixLocList(
213   \   bufnr('%'),
214   \   'foobar',
215   \   0,
216   \   [
217   \     {'text': 'a', 'lnum': '010', 'col': '010', 'end_col': '012'},
218   \     {'text': 'a', 'lnum': '010', 'col': '011', 'end_col': 12},
219   \   ],
220   \ )
221
222 Execute(FixLocList should pass on end_lnum values):
223   AssertEqual
224   \ [
225   \   {
226   \     'text': 'a',
227   \     'lnum': 7,
228   \     'col': 10,
229   \     'end_lnum': 10,
230   \     'end_col': 12,
231   \     'bufnr': bufnr('%'),
232   \     'vcol': 0,
233   \     'type': 'E',
234   \     'nr': -1,
235   \     'linter_name': 'foobar',
236   \   },
237   \   {
238   \     'text': 'a',
239   \     'lnum': 7,
240   \     'col': 11,
241   \     'end_lnum': 10,
242   \     'end_col': 12,
243   \     'bufnr': bufnr('%'),
244   \     'vcol': 0,
245   \     'type': 'E',
246   \     'nr': -1,
247   \     'linter_name': 'foobar',
248   \   },
249   \ ],
250   \ ale#engine#FixLocList(
251   \   bufnr('%'),
252   \   'foobar',
253   \   0,
254   \   [
255   \     {'text': 'a', 'lnum': '07', 'col': '010', 'end_col': '012', 'end_lnum': '010'},
256   \     {'text': 'a', 'lnum': '07', 'col': '011', 'end_col': 12, 'end_lnum': 10},
257   \   ],
258   \ )
259
260 Execute(FixLocList should allow subtypes to be set):
261   AssertEqual
262   \ [
263   \   {
264   \     'text': 'a',
265   \     'lnum': 10,
266   \     'col': 0,
267   \     'bufnr': bufnr('%'),
268   \     'vcol': 0,
269   \     'type': 'E',
270   \     'sub_type': 'style',
271   \     'nr': -1,
272   \     'linter_name': 'foobar',
273   \   },
274   \ ],
275   \ ale#engine#FixLocList(
276   \   bufnr('%'),
277   \   'foobar',
278   \   0,
279   \   [{'text': 'a', 'lnum': 11, 'sub_type': 'style'}],
280   \ )
281
282 Execute(FixLocList should accept filenames):
283   let b:other_bufnr = bufnr('/foo/bar/baz', 1)
284
285   " Make sure we actually get another buffer number, or the test is invalid.
286   AssertNotEqual -1, b:other_bufnr
287
288   call ale#test#SetFilename('test.txt')
289
290   AssertEqual
291   \ [
292   \   {
293   \     'text': 'a',
294   \     'lnum': 2,
295   \     'col': 0,
296   \     'bufnr': bufnr('%'),
297   \     'filename': expand('%:p'),
298   \     'vcol': 0,
299   \     'type': 'E',
300   \     'nr': -1,
301   \     'linter_name': 'foobar',
302   \   },
303   \   {
304   \     'text': 'a',
305   \     'lnum': 3,
306   \     'col': 0,
307   \     'bufnr': bufnr('%'),
308   \     'filename': expand('%:p'),
309   \     'vcol': 0,
310   \     'type': 'E',
311   \     'nr': -1,
312   \     'linter_name': 'foobar',
313   \   },
314   \   {
315   \     'text': 'a',
316   \     'lnum': 4,
317   \     'col': 0,
318   \     'bufnr': b:other_bufnr,
319   \     'filename': '/foo/bar/baz',
320   \     'vcol': 0,
321   \     'type': 'E',
322   \     'nr': -1,
323   \     'linter_name': 'foobar',
324   \   },
325   \   {
326   \     'text': 'a',
327   \     'lnum': 5,
328   \     'col': 0,
329   \     'bufnr': b:other_bufnr,
330   \     'filename': '/foo/bar/baz',
331   \     'vcol': 0,
332   \     'type': 'E',
333   \     'nr': -1,
334   \     'linter_name': 'foobar',
335   \   },
336   \ ],
337   \ ale#engine#FixLocList(
338   \   bufnr('%'),
339   \   'foobar',
340   \   0,
341   \   [
342   \     {'text': 'a', 'lnum': 2, 'filename': expand('%:p')},
343   \     {'text': 'a', 'lnum': 3, 'filename': expand('%:p')},
344   \     {'text': 'a', 'lnum': 4, 'filename': '/foo/bar/baz'},
345   \     {'text': 'a', 'lnum': 5, 'filename': '/foo/bar/baz'},
346   \   ],
347   \ )
348
349 Execute(FixLocList should interpret temporary filenames as being the current buffer):
350   let b:temp_name = tempname()
351
352   AssertEqual
353   \ [
354   \   {
355   \     'text': 'a',
356   \     'lnum': 2,
357   \     'col': 0,
358   \     'bufnr': bufnr(''),
359   \     'vcol': 0,
360   \     'type': 'E',
361   \     'nr': -1,
362   \     'linter_name': 'foobar',
363   \   },
364   \   {
365   \     'text': 'a',
366   \     'lnum': 3,
367   \     'col': 0,
368   \     'bufnr': bufnr(''),
369   \     'vcol': 0,
370   \     'type': 'E',
371   \     'nr': -1,
372   \     'linter_name': 'foobar',
373   \   },
374   \ ],
375   \ ale#engine#FixLocList(
376   \   bufnr(''),
377   \   'foobar',
378   \   0,
379   \   [
380   \     {'text': 'a', 'lnum': 2, 'filename': b:temp_name},
381   \     {'text': 'a', 'lnum': 3, 'filename': substitute(b:temp_name, '\\', '/', 'g')},
382   \   ],
383   \ )
384
385 Execute(The error code should be passed on):
386   AssertEqual
387   \ [
388   \   {
389   \     'text': 'a',
390   \     'lnum': 10,
391   \     'col': 0,
392   \     'bufnr': bufnr('%'),
393   \     'vcol': 0,
394   \     'type': 'E',
395   \     'nr': -1,
396   \     'linter_name': 'foobar',
397   \     'code': 'some-code'
398   \   },
399   \ ],
400   \ ale#engine#FixLocList(
401   \   bufnr('%'),
402   \   'foobar',
403   \   0,
404   \   [{'text': 'a', 'lnum': 11, 'code': 'some-code'}],
405   \ )
406
407 Execute(FixLocList should mark problems as coming from other sources if requested):
408   AssertEqual
409   \ [
410   \   {
411   \     'text': 'a',
412   \     'lnum': 2,
413   \     'col': 0,
414   \     'bufnr': bufnr('%'),
415   \     'vcol': 0,
416   \     'type': 'E',
417   \     'nr': -1,
418   \     'linter_name': 'foobar',
419   \     'from_other_source': 1,
420   \   },
421   \   {
422   \     'text': 'b',
423   \     'lnum': 2,
424   \     'col': 0,
425   \     'bufnr': bufnr('%'),
426   \     'vcol': 0,
427   \     'type': 'E',
428   \     'nr': -1,
429   \     'linter_name': 'foobar',
430   \     'from_other_source': 1,
431   \   },
432   \ ],
433   \ ale#engine#FixLocList(
434   \   bufnr('%'),
435   \   'foobar',
436   \   1,
437   \   [{'text': 'a', 'lnum': 2}, {'text': 'b', 'lnum': 2}],
438   \ )
439
440 Given(A file with Japanese multi-byte text):
441   はじめまして!
442   -私はワープです。
443 Execute(character positions should be converted to byte positions):
444   AssertEqual
445   \ [
446   \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 0, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
447   \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 1, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
448   \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 4, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
449   \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 7, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
450   \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 7, 'end_col': 13, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
451   \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 7, 'end_col': 13, 'end_lnum': 1, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
452   \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 7, 'end_col': 17, 'end_lnum': 2, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
453   \   {'lnum': 2, 'bufnr': bufnr(''), 'col': 17, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
454   \ ],
455   \ ale#engine#FixLocList(
456   \   bufnr('%'),
457   \   'foobar',
458   \   0,
459   \   [
460   \     {'text': 'a', 'lnum': 1, 'col': 0, 'vcol': 1},
461   \     {'text': 'a', 'lnum': 1, 'col': 1, 'vcol': 1},
462   \     {'text': 'a', 'lnum': 1, 'col': 2, 'vcol': 1},
463   \     {'text': 'a', 'lnum': 1, 'col': 3, 'vcol': 1},
464   \     {'text': 'a', 'lnum': 1, 'col': 3, 'end_col': 5, 'vcol': 1},
465   \     {'text': 'a', 'lnum': 1, 'col': 3, 'end_col': 5, 'end_lnum': 1, 'vcol': 1},
466   \     {'text': 'a', 'lnum': 1, 'col': 3, 'end_col': 7, 'end_lnum': 2, 'vcol': 1},
467   \     {'text': 'a', 'lnum': 2, 'col': 7, 'vcol': 1},
468   \   ],
469   \ )