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

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / test / fix / test_ale_fix.vader
1 Before:
2   Save g:ale_fixers
3   Save &shell
4   Save g:ale_enabled
5   Save g:ale_fix_on_save
6   Save g:ale_lint_on_save
7   Save g:ale_echo_cursor
8   Save g:ale_command_wrapper
9   Save g:ale_filename_mappings
10
11   silent! cd /testplugin/test/fix
12
13   unlet! b:ale_lint_on_save
14   let g:ale_enabled = 0
15   let g:ale_echo_cursor = 0
16   let g:ale_command_wrapper = ''
17   let g:ale_run_synchronously = 1
18   let g:ale_set_lists_synchronously = 1
19   let g:ale_fix_buffer_data = {}
20   let g:ale_fixers = {
21   \ 'testft': [],
22   \}
23   let g:ale_filename_mappings = {}
24
25   let g:pre_success = 0
26   let g:post_success = 0
27   augroup VaderTest
28     autocmd!
29     autocmd User ALEFixPre let g:pre_success = 1
30     autocmd User ALEFixPost let g:post_success = 1
31   augroup END
32
33   if !has('win32')
34     let &shell = '/bin/bash'
35   endif
36
37   call ale#test#SetDirectory('/testplugin/test')
38   call ale#test#SetFilename('test.txt')
39   call ale#linter#PreventLoading('testft')
40
41   function AddCarets(buffer, lines) abort
42     " map() is applied to the original lines here.
43     " This way, we can ensure that defensive copies are made.
44     return map(a:lines, '''^'' . v:val')
45   endfunction
46
47   function Capitalize(buffer, lines) abort
48     return map(a:lines, 'toupper(v:val)')
49   endfunction
50
51   function DoNothing(buffer, lines) abort
52     return 0
53   endfunction
54
55   function CatLine(buffer, lines) abort
56     return {'command': 'cat - <(echo d)'}
57   endfunction
58
59   function CatLineOneArg(buffer) abort
60     return {'command': 'cat - <(echo d)'}
61   endfunction
62
63   function CatLineDeferred(buffer, lines) abort
64     return ale#command#Run(a:buffer, 'echo', {
65     \ -> ale#command#Run(a:buffer, 'echo', {-> {'command': 'cat - <(echo d)'}})
66     \})
67   endfunction
68
69   function ReplaceWithTempFile(buffer, lines) abort
70     return {'command': 'echo x > %t', 'read_temporary_file': 1}
71   endfunction
72
73   function CatWithTempFile(buffer, lines) abort
74     return {'command': 'cat %t <(echo d)'}
75   endfunction
76
77   function EchoFilename(buffer, lines) abort
78     return {'command': 'echo %s'}
79   endfunction
80
81   function RemoveLastLine(buffer, lines) abort
82     return ['a', 'b']
83   endfunction
84
85   function RemoveLastLineOneArg(buffer) abort
86     return ['a', 'b']
87   endfunction
88
89   function! TestCallback(buffer, output)
90     return [{'lnum': 1, 'col': 1, 'text': 'xxx'}]
91   endfunction
92
93   " echo will output a single blank line, and we should ignore it.
94   function! IgnoredEmptyOutput(buffer, output)
95     return {'command': has('win32') ? 'echo(' : 'echo'}
96   endfunction
97
98   function! EchoLineNoPipe(buffer, output)
99     return {'command': 'echo new line', 'read_buffer': 0}
100   endfunction
101
102   function! SetUpLinters()
103     call ale#linter#Define('testft', {
104     \ 'name': 'testlinter',
105     \ 'callback': 'TestCallback',
106     \ 'executable': 'true',
107     \ 'command': 'true',
108     \})
109   endfunction
110
111   function GetLastMessage()
112     redir => l:output
113       silent mess
114     redir END
115
116     let l:lines = split(l:output, "\n")
117
118     return empty(l:lines) ? '' : l:lines[-1]
119   endfunction
120
121   function! FixWithJSONPostProcessing(buffer) abort
122     let l:ProcessWith = 'JSONPostProcessor'
123
124     " Test with lambdas where support is available.
125     if has('lambda')
126       let l:ProcessWith = {buffer, output -> JSONPostProcessor(buffer, output)}
127     endif
128
129     " Escaping needs to be handled specially for CMD on Windows.
130     let l:json_string = has('win32')
131     \ ? '{"output":["x","y","z"]}'
132     \ : ale#Escape('{"output": ["x", "y", "z"]}')
133
134     return {
135     \ 'command': 'echo ' . l:json_string,
136     \ 'read_buffer': 0,
137     \ 'process_with': l:ProcessWith,
138     \}
139   endfunction
140
141   function! JSONPostProcessor(buffer, output) abort
142     return json_decode(a:output[0]).output
143   endfunction
144
145 After:
146   Restore
147   unlet! g:test_filename
148   unlet! g:ale_run_synchronously
149   unlet! g:ale_set_lists_synchronously
150   unlet! g:ale_run_synchronously_callbacks
151   unlet! g:ale_emulate_job_failure
152   unlet! b:ale_fixers
153   unlet! b:ale_lint_on_save
154   unlet! b:ale_fix_on_save
155   unlet! b:ale_quitting
156   delfunction AddCarets
157   delfunction Capitalize
158   delfunction DoNothing
159   delfunction CatLine
160   delfunction CatLineOneArg
161   delfunction CatLineDeferred
162   delfunction ReplaceWithTempFile
163   delfunction CatWithTempFile
164   delfunction EchoFilename
165   delfunction RemoveLastLine
166   delfunction RemoveLastLineOneArg
167   delfunction TestCallback
168   delfunction SetUpLinters
169   delfunction GetLastMessage
170   delfunction IgnoredEmptyOutput
171   delfunction EchoLineNoPipe
172   delfunction FixWithJSONPostProcessing
173   delfunction JSONPostProcessor
174
175   augroup VaderTest
176     autocmd!
177   augroup END
178
179   augroup! VaderTest
180
181   call ale#test#RestoreDirectory()
182
183   call ale#fix#registry#ResetToDefaults()
184   call ale#linter#Reset()
185
186   setlocal buftype=nofile
187
188   if exists('g:test_filename') && filereadable(g:test_filename)
189     call delete(g:test_filename)
190   endif
191
192   call setloclist(0, [])
193
194   let g:ale_fix_buffer_data = {}
195
196   " Clear the messages between tests.
197   echomsg ''
198
199   if !exists('g:ale_command_wrapper')
200     let g:ale_command_wrapper = ''
201   endif
202
203 Given testft (A file with three lines):
204   a
205   b
206   c
207
208 Execute(ALEFix should complain when there are no functions to call):
209   ALEFix
210   call ale#test#FlushJobs()
211   AssertEqual 'No fixers have been defined. Try :ALEFixSuggest', GetLastMessage()
212
213 Execute(ALEFix should not complain when the command is run with a bang):
214   echom 'none'
215
216   ALEFix!
217   call ale#test#FlushJobs()
218   AssertEqual 'none', GetLastMessage()
219
220 Execute(ALEFix should apply simple functions):
221   let g:ale_fixers.testft = ['AddCarets']
222   ALEFix
223   call ale#test#FlushJobs()
224
225 Expect(The first function should be used):
226   ^a
227   ^b
228   ^c
229
230 Execute(Should apply filename mpapings):
231   " The command echos %s, and we'll map the current path so we can check
232   " that ALEFix applies filename mappings, end-to-end.
233   let g:ale_filename_mappings = {
234   \ 'echo_filename': [
235   \   [expand('%:p:h') . '/', '/some/fake/path/'],
236   \ ],
237   \}
238
239   call ale#fix#registry#Add('echo_filename', 'EchoFilename', [], 'echo filename')
240   let g:ale_fixers.testft = ['echo_filename']
241   ALEFix
242   call ale#test#FlushJobs()
243   " Remote trailing whitespace from the line.
244   call setline(1, substitute(getline(1), '[ \r]\+$', '', ''))
245
246 Expect(The mapped filename should be printed):
247   /some/fake/path/test.txt
248
249 Execute(ALEFix should apply simple functions in a chain):
250   let g:ale_fixers.testft = ['AddCarets', 'Capitalize']
251   ALEFix
252   call ale#test#FlushJobs()
253
254 Expect(Both functions should be used):
255   ^A
256   ^B
257   ^C
258
259 Execute(ALEFix should allow 0 to be returned to skip functions):
260   let g:ale_fixers.testft = ['DoNothing', 'Capitalize']
261   ALEFix
262   call ale#test#FlushJobs()
263
264 Expect(Only the second function should be applied):
265   A
266   B
267   C
268
269 Execute(The * fixers shouldn't be used if an empty list is set for fixers):
270   let g:ale_fixers.testft = []
271   let g:ale_fixers['*'] = ['Capitalize']
272   ALEFix
273   call ale#test#FlushJobs()
274
275 Expect(Nothing should be changed):
276   a
277   b
278   c
279
280 Execute(* fixers should be used if no filetype is matched):
281   let g:ale_fixers = {'*': ['Capitalize']}
282   ALEFix
283   call ale#test#FlushJobs()
284
285 Expect(The file should be changed):
286   A
287   B
288   C
289
290 Execute(ALEFix should allow commands to be run):
291   if has('win32')
292     " Just skip this test on Windows, we can't run it.
293     call setline(1, ['a', 'b', 'c', 'd'])
294   else
295     let g:ale_fixers.testft = ['CatLine']
296     ALEFix
297     call ale#test#FlushJobs()
298   endif
299
300 Expect(An extra line should be added):
301   a
302   b
303   c
304   d
305
306 Execute(ALEFix should use fixers passed in commandline when provided):
307   let g:ale_fixers.testft = ['RemoveLastLine']
308   ALEFix AddCarets Capitalize
309   call ale#test#FlushJobs()
310
311 Expect(Only fixers passed via command line should be run):
312   ^A
313   ^B
314   ^C
315
316 Execute(ALEFix should allow temporary files to be read):
317   if has('win32')
318     " Just skip this test on Windows, we can't run it.
319     call setline(1, ['x'])
320     2,3d
321   else
322     let g:ale_fixers.testft = ['ReplaceWithTempFile']
323     ALEFix
324     call ale#test#FlushJobs()
325   endif
326
327 Expect(The line we wrote to the temporary file should be used here):
328   x
329
330 Execute(ALEFix should not read the temporary file when the option is not set):
331   if has('win32')
332     " Just skip this test on Windows, we can't run it.
333     call setline(1, ['a', 'b', 'c', 'd'])
334   else
335     let g:ale_fixers.testft = ['CatWithTempFile']
336     ALEFix
337     call ale#test#FlushJobs()
338   endif
339
340 Expect(An extra line should be added):
341   a
342   b
343   c
344   d
345
346 Execute(ALEFix should allow jobs and simple functions to be combined):
347   if has('win32')
348     " Just skip this test on Windows, we can't run it.
349     call setline(1, ['X'])
350     2,3d
351   else
352     let g:ale_fixers.testft = ['ReplaceWithTempFile', 'Capitalize']
353     ALEFix
354     call ale#test#FlushJobs()
355   endif
356
357 Expect(The lines from the temporary file should be modified):
358   X
359
360 Execute(ALEFix should send lines modified by functions to jobs):
361   if has('win32')
362     " Just skip this test on Windows, we can't run it.
363     call setline(1, ['A', 'B', 'C', 'd'])
364   else
365     let g:ale_fixers.testft = ['Capitalize', 'CatLine']
366     ALEFix
367     call ale#test#FlushJobs()
368   endif
369
370 Expect(The lines should first be modified by the function, then the job):
371   A
372   B
373   C
374   d
375
376 Execute(ALEFix should skip commands when jobs fail to run):
377   let g:ale_emulate_job_failure = 1
378   let g:ale_fixers.testft = ['CatLine', 'Capitalize']
379   ALEFix
380   call ale#test#FlushJobs()
381
382 Expect(Only the second function should be applied):
383   A
384   B
385   C
386
387 Execute(ALEFix should handle strings for selecting a single function):
388   let g:ale_fixers.testft = 'AddCarets'
389   ALEFix
390   call ale#test#FlushJobs()
391
392 Expect(The first function should be used):
393   ^a
394   ^b
395   ^c
396
397 Execute(ALEFix should use functions from the registry):
398   call ale#fix#registry#Add('add_carets', 'AddCarets', [], 'Add some carets')
399   let g:ale_fixers.testft = ['add_carets']
400   ALEFix
401   call ale#test#FlushJobs()
402
403 Expect(The registry function should be used):
404   ^a
405   ^b
406   ^c
407
408 Execute(ALEFix should be able to remove the last line for files):
409   let g:ale_fixers.testft = ['RemoveLastLine']
410   ALEFix
411   call ale#test#FlushJobs()
412
413 Expect(There should be only two lines):
414   a
415   b
416
417 Execute(ALEFix should accept funcrefs):
418   let g:ale_fixers.testft = [function('RemoveLastLine')]
419   ALEFix
420   call ale#test#FlushJobs()
421
422 Expect(There should be only two lines):
423   a
424   b
425
426 Execute(ALEFix should accept lambdas):
427   if has('nvim')
428     " NeoVim 0.1.7 can't interpret lambdas correctly, so just set the lines
429     " to make the test pass.
430     call setline(1, ['a', 'b', 'c', 'd'])
431   else
432     let g:ale_fixers.testft = [{buffer, lines -> lines + ['d']}]
433     ALEFix
434     call ale#test#FlushJobs()
435   endif
436
437 Expect(There should be an extra line):
438   a
439   b
440   c
441   d
442
443 Execute(ALEFix should user buffer-local fixer settings):
444   let g:ale_fixers.testft = ['AddCarets', 'Capitalize']
445   let b:ale_fixers = {'testft': ['RemoveLastLine']}
446   ALEFix
447   call ale#test#FlushJobs()
448
449 Expect(There should be only two lines):
450   a
451   b
452
453 Execute(ALEFix should allow Lists to be used for buffer-local fixer settings):
454   let g:ale_fixers.testft = ['AddCarets', 'Capitalize']
455   let b:ale_fixers = ['RemoveLastLine']
456   ALEFix
457   call ale#test#FlushJobs()
458
459 Expect(There should be only two lines):
460   a
461   b
462
463 Given testft (A file with three lines):
464   a
465   b
466   c
467
468 Execute(ALEFix should fix files on the save event):
469   let g:ale_fix_on_save = 1
470   let g:ale_lint_on_save = 1
471   let g:ale_enabled = 1
472
473   let g:test_filename = tempname()
474   execute 'noautocmd silent file ' . fnameescape(g:test_filename)
475   call writefile(getline(1, '$'), g:test_filename)
476
477   let g:ale_fixers.testft = ['Capitalize']
478
479   " We have to set the buftype to empty so the file will be written.
480   setlocal buftype=
481
482   call SetUpLinters()
483   call ale#events#SaveEvent(bufnr(''))
484   call ale#test#FlushJobs()
485
486   " We should save the file.
487   AssertEqual ['A', 'B', 'C'], readfile(g:test_filename)
488   Assert !&modified, 'The file was marked as ''modified'''
489
490   if !has('win32')
491     " We should have run the linter.
492     AssertEqual [{
493     \   'bufnr': bufnr('%'),
494     \   'lnum': 1,
495     \   'vcol': 0,
496     \   'col': 1,
497     \   'text': 'xxx',
498     \   'type': 'E',
499     \   'nr': -1,
500     \   'pattern': '',
501     \   'valid': 1,
502     \}], ale#test#GetLoclistWithoutNewerKeys()
503   endif
504
505 Expect(The buffer should be modified):
506   A
507   B
508   C
509
510 Given testft (A file with three lines):
511   a
512   b
513   c
514
515 Execute(ALEFix should run the linters with b:ale_lint_on_save = 1):
516   let g:ale_fix_on_save = 0
517   let b:ale_fix_on_save = 1
518   let g:ale_lint_on_save = 1
519   let g:ale_enabled = 1
520
521   let g:test_filename = tempname()
522   execute 'noautocmd silent file ' . fnameescape(g:test_filename)
523   call writefile(getline(1, '$'), g:test_filename)
524
525   let g:ale_fixers.testft = ['Capitalize']
526
527   " We have to set the buftype to empty so the file will be written.
528   setlocal buftype=
529
530   call SetUpLinters()
531   call ale#events#SaveEvent(bufnr(''))
532   call ale#test#FlushJobs()
533
534   " We should save the file.
535   AssertEqual ['A', 'B', 'C'], readfile(g:test_filename)
536   Assert !&modified, 'The file was marked as ''modified'''
537
538   if !has('win32')
539     " We should have run the linter.
540     AssertEqual [{
541     \   'bufnr': bufnr('%'),
542     \   'lnum': 1,
543     \   'vcol': 0,
544     \   'col': 1,
545     \   'text': 'xxx',
546     \   'type': 'E',
547     \   'nr': -1,
548     \   'pattern': '',
549     \   'valid': 1,
550     \}], ale#test#GetLoclistWithoutNewerKeys()
551   endif
552
553 Expect(The buffer should be modified):
554   A
555   B
556   C
557
558 Execute(ALEFix should not fix files on :wq):
559   let g:ale_fix_on_save = 1
560   let g:ale_lint_on_save = 1
561   let g:ale_enabled = 1
562
563   let g:test_filename = tempname()
564   execute 'noautocmd silent file ' . fnameescape(g:test_filename)
565   call writefile(getline(1, '$'), g:test_filename)
566
567   let g:ale_fixers.testft = ['Capitalize']
568
569   " We have to set the buftype to empty so the file will be written.
570   setlocal buftype=
571
572   call ale#events#QuitEvent(bufnr(''))
573
574   call SetUpLinters()
575   call ale#events#SaveEvent(bufnr(''))
576
577   " We should save the file.
578   AssertEqual ['a', 'b', 'c'], readfile(g:test_filename)
579   Assert &modified, 'The was not marked as ''modified'''
580
581   " We should not run the linter.
582   AssertEqual [], ale#test#GetLoclistWithoutNewerKeys()
583
584 Expect(The buffer should not be modified):
585   a
586   b
587   c
588
589 Given testft (A file with three lines):
590   a
591   b
592   c
593
594 Execute(ALEFix should still lint with no linters to be applied):
595   let g:ale_fix_on_save = 1
596   let g:ale_lint_on_save = 1
597   let g:ale_enabled = 1
598
599   let g:test_filename = tempname()
600   execute 'noautocmd silent file ' . fnameescape(g:test_filename)
601
602   let g:ale_fixers.testft = []
603
604   call SetUpLinters()
605   call ale#events#SaveEvent(bufnr(''))
606   call ale#test#FlushJobs()
607
608   Assert !filereadable(g:test_filename), 'The file should not have been saved'
609
610   if !has('win32')
611     " We have run the linter.
612     AssertEqual [{
613     \   'bufnr': bufnr('%'),
614     \   'lnum': 1,
615     \   'vcol': 0,
616     \   'col': 1,
617     \   'text': 'xxx',
618     \   'type': 'E',
619     \   'nr': -1,
620     \   'pattern': '',
621     \   'valid': 1,
622     \}], ale#test#GetLoclistWithoutNewerKeys()
623   endif
624
625 Expect(The buffer should be the same):
626   a
627   b
628   c
629
630 Execute(ALEFix should still lint when nothing was fixed on save):
631   let g:ale_fix_on_save = 1
632   let g:ale_lint_on_save = 1
633   let g:ale_enabled = 1
634
635   let g:test_filename = tempname()
636   execute 'noautocmd silent file ' . fnameescape(g:test_filename)
637
638   let g:ale_fixers.testft = ['DoNothing']
639
640   call SetUpLinters()
641   call ale#events#SaveEvent(bufnr(''))
642   call ale#test#FlushJobs()
643
644   Assert !filereadable(g:test_filename), 'The file should not have been saved'
645
646   if !has('win32')
647     " We should have run the linter.
648     AssertEqual [{
649     \   'bufnr': bufnr('%'),
650     \   'lnum': 1,
651     \   'vcol': 0,
652     \   'col': 1,
653     \   'text': 'xxx',
654     \   'type': 'E',
655     \   'nr': -1,
656     \   'pattern': '',
657     \   'valid': 1,
658     \}], ale#test#GetLoclistWithoutNewerKeys()
659   endif
660
661 Expect(The buffer should be the same):
662   a
663   b
664   c
665
666 Execute(ALEFix should not lint the buffer on save if linting on save is disabled globally):
667   let g:ale_fix_on_save = 1
668   let g:ale_lint_on_save = 0
669   let g:ale_enabled = 1
670
671   let g:test_filename = tempname()
672   execute 'noautocmd silent file ' . fnameescape(g:test_filename)
673
674   let g:ale_fixers.testft = ['DoNothing']
675
676   call SetUpLinters()
677   call ale#events#SaveEvent(bufnr(''))
678   call ale#test#FlushJobs()
679
680   Assert !filereadable(g:test_filename), 'The file should not have been saved'
681
682   AssertEqual [], ale#test#GetLoclistWithoutNewerKeys()
683
684 Expect(The buffer should be the same):
685   a
686   b
687   c
688
689 Execute(ALEFix should not lint the buffer on save if linting on save is disabled locally):
690   let g:ale_fix_on_save = 1
691   let b:ale_lint_on_save = 0
692   let g:ale_enabled = 1
693
694   let g:test_filename = tempname()
695   execute 'noautocmd silent file ' . fnameescape(g:test_filename)
696
697   let g:ale_fixers.testft = ['DoNothing']
698
699   call SetUpLinters()
700   call ale#events#SaveEvent(bufnr(''))
701   call ale#test#FlushJobs()
702
703   Assert !filereadable(g:test_filename), 'The file should not have been saved'
704
705   AssertEqual [], ale#test#GetLoclistWithoutNewerKeys()
706
707 Expect(The buffer should be the same):
708   a
709   b
710   c
711
712 Given testft (A file with three lines):
713   a
714   b
715   c
716
717 Execute(ale#fix#InitBufferData() should set up the correct data):
718   let g:test_filename = tempname()
719   execute 'noautocmd silent file ' . fnameescape(g:test_filename)
720
721   call ale#fix#InitBufferData(bufnr(''), 'save_file')
722
723   AssertEqual {
724   \ bufnr(''): {
725   \   'temporary_directory_list': [],
726   \   'done': 0,
727   \   'lines_before': ['a', 'b', 'c'],
728   \   'should_save': 1,
729   \   'ignore_file_changed_errors': 0,
730   \ },
731   \}, g:ale_fix_buffer_data
732
733   call ale#fix#InitBufferData(bufnr(''), '!')
734
735   AssertEqual {
736   \ bufnr(''): {
737   \   'temporary_directory_list': [],
738   \   'done': 0,
739   \   'lines_before': ['a', 'b', 'c'],
740   \   'should_save': 0,
741   \   'ignore_file_changed_errors': 1,
742   \ },
743   \}, g:ale_fix_buffer_data
744
745 Execute(ALEFix simple functions should be able to accept one argument, the buffer):
746   let g:ale_fixers.testft = ['RemoveLastLineOneArg']
747   ALEFix
748   call ale#test#FlushJobs()
749
750 Expect(There should be only two lines):
751   a
752   b
753
754 Execute(ALEFix should modify a buffer that is not modifiable, if it becomes modifiable later):
755   let g:ale_fixers.testft = ['RemoveLastLineOneArg']
756
757   set nomodifiable
758   ALEFix
759   call ale#test#FlushJobs()
760   set modifiable
761   call ale#fix#ApplyQueuedFixes(bufnr(''))
762
763 Expect(There should be only two lines):
764   a
765   b
766
767 Execute(b:ale_fix_on_save = 1 should override g:ale_fix_on_save = 0):
768   let g:ale_fix_on_save = 0
769   let b:ale_fix_on_save = 1
770
771   let g:ale_fixers.testft = ['RemoveLastLineOneArg']
772   call ale#events#SaveEvent(bufnr(''))
773
774 Expect(There should be only two lines):
775   a
776   b
777
778 Execute(b:ale_fix_on_save = 0 should override g:ale_fix_on_save = 1):
779   let g:ale_fix_on_save = 1
780   let b:ale_fix_on_save = 0
781
782   let g:ale_fixers.testft = ['RemoveLastLineOneArg']
783   call ale#events#SaveEvent(bufnr(''))
784
785 Expect(The lines should be the same):
786   a
787   b
788   c
789
790 Execute(ALEFix functions returning jobs should be able to accept one argument):
791   if has('win32')
792     " Just skip this test on Windows, we can't run it.
793     call setline(1, ['a', 'b', 'c', 'd'])
794   else
795     let g:ale_fixers.testft = ['CatLine']
796     ALEFix
797     call ale#test#FlushJobs()
798   endif
799
800 Expect(An extra line should be added):
801   a
802   b
803   c
804   d
805
806 Execute(ALE should print a message telling you something isn't a valid fixer when you type some nonsense):
807   let g:ale_fixers.testft = ['CatLine', 'invalidname']
808   ALEFix
809   call ale#test#FlushJobs()
810
811   AssertEqual 'There is no fixer named `invalidname`. Check :ALEFixSuggest', GetLastMessage()
812
813 Execute(ALE should complain about invalid fixers with minuses in the name):
814   let g:ale_fixers.testft = ['foo-bar']
815   ALEFix
816   call ale#test#FlushJobs()
817
818   AssertEqual 'There is no fixer named `foo-bar`. Check :ALEFixSuggest', GetLastMessage()
819
820 Execute(ALE should tolerate valid fixers with minuses in the name):
821   let g:ale_fixers.testft = ['prettier-standard']
822   ALEFix
823   call ale#test#FlushJobs()
824
825 Execute(Empty output should be ignored):
826   let g:ale_fixers.testft = ['IgnoredEmptyOutput']
827   ALEFix
828   call ale#test#FlushJobs()
829
830 Expect(The lines should be the same):
831   a
832   b
833   c
834
835 Execute(A temporary file shouldn't be piped into the command when disabled):
836   let g:ale_fixers.testft = ['EchoLineNoPipe']
837   ALEFix
838   call ale#test#FlushJobs()
839
840   AssertEqual
841   \ string(ale#job#PrepareCommand(bufnr(''), 'echo new line')),
842   \ string(ale#history#Get(bufnr(''))[-1].command)
843
844   " Remove trailing whitespace for Windows.
845   if has('win32')
846     %s/[[:space:]]*$//g
847   endif
848
849 Expect(The new line should be used):
850   new line
851
852 Execute(Post-processing should work):
853   let g:ale_fixers.testft = ['FixWithJSONPostProcessing']
854   ALEFix
855   call ale#test#FlushJobs()
856
857 Expect(The lines in the JSON should be used):
858   x
859   y
860   z
861
862 Execute(ALEFix should apply autocmds):
863   let g:ale_fixers.testft = ['AddCarets']
864   ALEFix
865   call ale#test#FlushJobs()
866
867   AssertEqual g:pre_success, 1
868   AssertEqual g:post_success, 1
869
870 Execute(ALEFix should support ale#command#Run):
871   if has('win32')
872     " Just skip this test on Windows, we can't run it.
873     call setline(1, ['a', 'b', 'c', 'd'])
874   else
875     let g:ale_fixers.testft = ['CatLineDeferred']
876     ALEFix
877     call ale#test#FlushJobs()
878   endif
879
880 Expect(The extra line should be added):
881   a
882   b
883   c
884   d