summaryrefslogtreecommitdiff
path: root/test/test_loclist_corrections.vader
blob: d53b1411dc9a1c8405a85bf80572413004bb4ede (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
Before:
  Save g:ale_filename_mappings

  let g:ale_filename_mappings = {}

After:
  unlet! b:temp_name
  unlet! b:other_bufnr

  Restore


Execute(FixLocList should map filenames):
  " Paths converted back into temporary filenames shouldn't be included.
  let g:ale_filename_mappings = {
  \ 'linter2': [['/xxx/', '/data/']],
  \ 'linter1': [
  \   ['/bar/', '/data/special/'],
  \   ['/foo/', '/data/'],
  \   [
  \     ale#path#Simplify(fnamemodify(ale#util#Tempname(), ':h:h')) . '/',
  \     '/x-tmp/',
  \   ],
  \ ],
  \}

  AssertEqual
  \ [
  \   '/foo/file.txt',
  \   v:null,
  \   '/bar/file.txt',
  \ ],
  \ map(
  \   ale#engine#FixLocList(
  \     bufnr('%'),
  \     'linter1',
  \     0,
  \     [
  \       {'text': 'x', 'lnum': 1, 'filename': '/data/file.txt'},
  \       {'text': 'x', 'lnum': 1, 'filename': '/x-tmp/file.txt'},
  \       {'text': 'x', 'lnum': 1, 'filename': '/data/special/file.txt'},
  \     ],
  \   ),
  \   'get(v:val, ''filename'', v:null)',
  \ )


Given foo (Some file with lines to count):
  foo12345678
  bar12345678
  baz12345678
  four12345678
  five12345678
  six12345678
  seven12345678
  eight12345678
  nine12345678
  ten12345678

Execute(FixLocList should set all the default values correctly):
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 2,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \   {
  \     'text': 'b',
  \     'lnum': 2,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [{'text': 'a', 'lnum': 2}, {'text': 'b', 'lnum': 2}],
  \ )

Execute(FixLocList should use the values we supply):
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 3,
  \     'col': 4,
  \     'bufnr': 10000,
  \     'vcol': 0,
  \     'type': 'W',
  \     'nr': 42,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [{
  \     'text': 'a',
  \     'lnum': 3,
  \     'col': 4,
  \     'bufnr': 10000,
  \     'vcol': 1,
  \     'type': 'W',
  \     'nr': 42,
  \   }],
  \ )

Execute(FixLocList should set items with lines beyond the end to the last line):
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 10,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [{'text': 'a', 'lnum': 11}],
  \ )

Execute(FixLocList should move line 0 to line 1):
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 1,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [{'text': 'a', 'lnum': 0}],
  \ )

Execute(FixLocList should convert line and column numbers correctly):
  " The numbers should be 10, not 8 as octals.
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 10,
  \     'col': 10,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [{'text': 'a', 'lnum': '010', 'col': '010'}],
  \ )

Execute(FixLocList should pass on end_col values):
  " The numbers should be 10, not 8 as octals.
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 10,
  \     'col': 10,
  \     'end_col': 12,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \   {
  \     'text': 'a',
  \     'lnum': 10,
  \     'col': 11,
  \     'end_col': 12,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [
  \     {'text': 'a', 'lnum': '010', 'col': '010', 'end_col': '012'},
  \     {'text': 'a', 'lnum': '010', 'col': '011', 'end_col': 12},
  \   ],
  \ )

Execute(FixLocList should pass on end_lnum values):
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 10,
  \     'col': 10,
  \     'end_lnum': 13,
  \     'end_col': 12,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \   {
  \     'text': 'a',
  \     'lnum': 10,
  \     'col': 11,
  \     'end_lnum': 13,
  \     'end_col': 12,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [
  \     {'text': 'a', 'lnum': '010', 'col': '010', 'end_col': '012', 'end_lnum': '013'},
  \     {'text': 'a', 'lnum': '010', 'col': '011', 'end_col': 12, 'end_lnum': 13},
  \   ],
  \ )

Execute(FixLocList should allow subtypes to be set):
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 10,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'sub_type': 'style',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [{'text': 'a', 'lnum': 11, 'sub_type': 'style'}],
  \ )

Execute(FixLocList should accept filenames):
  let b:other_bufnr = bufnr('/foo/bar/baz', 1)

  " Make sure we actually get another buffer number, or the test is invalid.
  AssertNotEqual -1, b:other_bufnr

  call ale#test#SetFilename('test.txt')

  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 2,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'filename': expand('%:p'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \   {
  \     'text': 'a',
  \     'lnum': 3,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'filename': expand('%:p'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \   {
  \     'text': 'a',
  \     'lnum': 4,
  \     'col': 0,
  \     'bufnr': b:other_bufnr,
  \     'filename': '/foo/bar/baz',
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \   {
  \     'text': 'a',
  \     'lnum': 5,
  \     'col': 0,
  \     'bufnr': b:other_bufnr,
  \     'filename': '/foo/bar/baz',
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [
  \     {'text': 'a', 'lnum': 2, 'filename': expand('%:p')},
  \     {'text': 'a', 'lnum': 3, 'filename': expand('%:p')},
  \     {'text': 'a', 'lnum': 4, 'filename': '/foo/bar/baz'},
  \     {'text': 'a', 'lnum': 5, 'filename': '/foo/bar/baz'},
  \   ],
  \ )

Execute(FixLocList should interpret temporary filenames as being the current buffer):
  let b:temp_name = tempname()

  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 2,
  \     'col': 0,
  \     'bufnr': bufnr(''),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \   {
  \     'text': 'a',
  \     'lnum': 3,
  \     'col': 0,
  \     'bufnr': bufnr(''),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr(''),
  \   'foobar',
  \   0,
  \   [
  \     {'text': 'a', 'lnum': 2, 'filename': b:temp_name},
  \     {'text': 'a', 'lnum': 3, 'filename': substitute(b:temp_name, '\\', '/', 'g')},
  \   ],
  \ )

Execute(The error code should be passed on):
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 10,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \     'code': 'some-code'
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [{'text': 'a', 'lnum': 11, 'code': 'some-code'}],
  \ )

Execute(FixLocList should mark problems as coming from other sources if requested):
  AssertEqual
  \ [
  \   {
  \     'text': 'a',
  \     'lnum': 2,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \     'from_other_source': 1,
  \   },
  \   {
  \     'text': 'b',
  \     'lnum': 2,
  \     'col': 0,
  \     'bufnr': bufnr('%'),
  \     'vcol': 0,
  \     'type': 'E',
  \     'nr': -1,
  \     'linter_name': 'foobar',
  \     'from_other_source': 1,
  \   },
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   1,
  \   [{'text': 'a', 'lnum': 2}, {'text': 'b', 'lnum': 2}],
  \ )

Given(A file with Japanese multi-byte text):
  はじめまして!
  -私はワープです。
Execute(character positions should be converted to byte positions):
  AssertEqual
  \ [
  \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 0, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
  \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 1, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
  \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 4, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
  \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 7, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
  \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 7, 'end_col': 13, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
  \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 7, 'end_col': 13, 'end_lnum': 1, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
  \   {'lnum': 1, 'bufnr': bufnr(''), 'col': 7, 'end_col': 17, 'end_lnum': 2, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
  \   {'lnum': 2, 'bufnr': bufnr(''), 'col': 17, 'linter_name': 'foobar', 'nr': -1, 'type': 'E', 'vcol': 0, 'text': 'a'},
  \ ],
  \ ale#engine#FixLocList(
  \   bufnr('%'),
  \   'foobar',
  \   0,
  \   [
  \     {'text': 'a', 'lnum': 1, 'col': 0, 'vcol': 1},
  \     {'text': 'a', 'lnum': 1, 'col': 1, 'vcol': 1},
  \     {'text': 'a', 'lnum': 1, 'col': 2, 'vcol': 1},
  \     {'text': 'a', 'lnum': 1, 'col': 3, 'vcol': 1},
  \     {'text': 'a', 'lnum': 1, 'col': 3, 'end_col': 5, 'vcol': 1},
  \     {'text': 'a', 'lnum': 1, 'col': 3, 'end_col': 5, 'end_lnum': 1, 'vcol': 1},
  \     {'text': 'a', 'lnum': 1, 'col': 3, 'end_col': 7, 'end_lnum': 2, 'vcol': 1},
  \     {'text': 'a', 'lnum': 2, 'col': 7, 'vcol': 1},
  \   ],
  \ )