2017-05-18 08:21:14 -04:00
|
|
|
Before:
|
2017-05-30 16:32:51 -04:00
|
|
|
Save g:ale_fixers
|
|
|
|
Save &shell
|
|
|
|
Save g:ale_enabled
|
|
|
|
Save g:ale_fix_on_save
|
|
|
|
Save g:ale_lint_on_save
|
|
|
|
Save g:ale_echo_cursor
|
|
|
|
|
2017-11-22 09:55:08 -05:00
|
|
|
silent! cd /testplugin/test/fix
|
2017-05-30 16:32:51 -04:00
|
|
|
|
2017-05-19 10:24:21 -04:00
|
|
|
let g:ale_enabled = 0
|
2017-05-30 16:32:51 -04:00
|
|
|
let g:ale_echo_cursor = 0
|
2017-05-18 08:21:14 -04:00
|
|
|
let g:ale_run_synchronously = 1
|
2017-10-23 18:09:40 -04:00
|
|
|
let g:ale_set_lists_synchronously = 1
|
2017-05-30 17:15:24 -04:00
|
|
|
let g:ale_fix_buffer_data = {}
|
2017-05-18 08:21:14 -04:00
|
|
|
let g:ale_fixers = {
|
|
|
|
\ 'testft': [],
|
|
|
|
\}
|
2017-10-23 18:09:40 -04:00
|
|
|
|
2017-12-23 08:13:55 -05:00
|
|
|
let g:pre_success = 0
|
|
|
|
let g:post_success = 0
|
|
|
|
augroup VaderTest
|
|
|
|
autocmd!
|
|
|
|
autocmd User ALEFixPre let g:pre_success = 1
|
|
|
|
autocmd User ALEFixPost let g:post_success = 1
|
|
|
|
augroup end
|
|
|
|
|
2017-10-23 18:09:40 -04:00
|
|
|
if !has('win32')
|
|
|
|
let &shell = '/bin/bash'
|
|
|
|
endif
|
|
|
|
|
|
|
|
call ale#test#SetDirectory('/testplugin/test')
|
|
|
|
call ale#test#SetFilename('test.txt')
|
2017-05-18 08:21:14 -04:00
|
|
|
|
|
|
|
function AddCarets(buffer, lines) abort
|
|
|
|
" map() is applied to the original lines here.
|
|
|
|
" This way, we can ensure that defensive copies are made.
|
|
|
|
return map(a:lines, '''^'' . v:val')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function AddDollars(buffer, lines) abort
|
|
|
|
return map(a:lines, '''$'' . v:val')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function DoNothing(buffer, lines) abort
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function CatLine(buffer, lines) abort
|
|
|
|
return {'command': 'cat - <(echo d)'}
|
|
|
|
endfunction
|
|
|
|
|
2017-06-06 18:13:53 -04:00
|
|
|
function CatLineOneArg(buffer) abort
|
|
|
|
return {'command': 'cat - <(echo d)'}
|
|
|
|
endfunction
|
|
|
|
|
2017-05-18 08:21:14 -04:00
|
|
|
function ReplaceWithTempFile(buffer, lines) abort
|
|
|
|
return {'command': 'echo x > %t', 'read_temporary_file': 1}
|
|
|
|
endfunction
|
|
|
|
|
2017-05-19 04:53:28 -04:00
|
|
|
function RemoveLastLine(buffer, lines) abort
|
|
|
|
return ['a', 'b']
|
|
|
|
endfunction
|
2017-05-19 10:24:21 -04:00
|
|
|
|
2017-06-06 18:13:53 -04:00
|
|
|
function RemoveLastLineOneArg(buffer) abort
|
|
|
|
return ['a', 'b']
|
|
|
|
endfunction
|
|
|
|
|
2017-05-30 16:32:51 -04:00
|
|
|
function! TestCallback(buffer, output)
|
|
|
|
return [{'lnum': 1, 'col': 1, 'text': 'xxx'}]
|
|
|
|
endfunction
|
|
|
|
|
2017-11-07 18:20:14 -05:00
|
|
|
function! FirstChainCallback(buffer)
|
|
|
|
return {'command': 'echo echoline', 'chain_with': 'SecondChainCallback'}
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! FirstChainCallbackSkipped(buffer)
|
2017-11-22 17:39:43 -05:00
|
|
|
let l:ChainWith = 'SecondChainCallback'
|
|
|
|
|
|
|
|
" Test with lambdas where support is available.
|
|
|
|
if has('lambda')
|
|
|
|
let l:ChainWith = {buffer, output -> SecondChainCallback(buffer, output)}
|
|
|
|
endif
|
|
|
|
|
|
|
|
return {'command': '', 'chain_with': l:ChainWith}
|
2017-11-07 18:20:14 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! FirstChainCallbackSecondSkipped(buffer)
|
|
|
|
return {'command': 'echo skipit', 'chain_with': 'SecondChainCallback'}
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! SecondChainCallback(buffer, output)
|
|
|
|
let l:previous_line = empty(a:output)
|
|
|
|
\ ? 'emptydefault'
|
|
|
|
\ : join(split(a:output[0]))
|
|
|
|
|
|
|
|
if l:previous_line is# 'skipit'
|
|
|
|
return {'command': '', 'chain_with': 'ThirdChainCallback'}
|
|
|
|
endif
|
|
|
|
|
|
|
|
return {
|
|
|
|
\ 'command': 'echo ' . l:previous_line,
|
|
|
|
\ 'chain_with': 'ThirdChainCallback',
|
|
|
|
\}
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ThirdChainCallback(buffer, output, input)
|
|
|
|
let l:previous_line = empty(a:output)
|
|
|
|
\ ? 'thirddefault'
|
|
|
|
\ : join(split(a:output[0]))
|
|
|
|
|
|
|
|
return a:input + [l:previous_line]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ChainWhereLastIsSkipped(buffer)
|
|
|
|
return {'command': 'echo echoline', 'chain_with': 'ChainEndSkipped'}
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ChainEndSkipped(buffer, output)
|
|
|
|
return {'command': ''}
|
|
|
|
endfunction
|
|
|
|
|
2017-11-22 07:01:21 -05:00
|
|
|
" echo will output a single blank line, and we should ingore it.
|
|
|
|
function! IgnoredEmptyOutput(buffer, output)
|
2017-11-22 07:41:16 -05:00
|
|
|
return {'command': has('win32') ? 'echo(' : 'echo'}
|
2017-11-22 07:01:21 -05:00
|
|
|
endfunction
|
|
|
|
|
2017-11-22 08:01:13 -05:00
|
|
|
function! EchoLineNoPipe(buffer, output)
|
|
|
|
return {'command': 'echo new line', 'read_buffer': 0}
|
|
|
|
endfunction
|
|
|
|
|
2017-05-30 16:32:51 -04:00
|
|
|
function! SetUpLinters()
|
|
|
|
call ale#linter#Define('testft', {
|
|
|
|
\ 'name': 'testlinter',
|
|
|
|
\ 'callback': 'TestCallback',
|
|
|
|
\ 'executable': 'true',
|
|
|
|
\ 'command': 'true',
|
|
|
|
\})
|
|
|
|
endfunction
|
|
|
|
|
2017-11-07 14:47:20 -05:00
|
|
|
function GetLastMessage()
|
|
|
|
redir => l:output
|
|
|
|
silent mess
|
|
|
|
redir END
|
|
|
|
|
|
|
|
let l:lines = split(l:output, "\n")
|
|
|
|
|
|
|
|
return empty(l:lines) ? '' : l:lines[-1]
|
|
|
|
endfunction
|
|
|
|
|
2017-11-22 17:32:53 -05:00
|
|
|
function! FixWithJSONPostProcessing(buffer) abort
|
|
|
|
let l:ProcessWith = 'JSONPostProcessor'
|
|
|
|
|
|
|
|
" Test with lambdas where support is available.
|
|
|
|
if has('lambda')
|
|
|
|
let l:ProcessWith = {buffer, output -> JSONPostProcessor(buffer, output)}
|
|
|
|
endif
|
|
|
|
|
2017-11-22 18:45:51 -05:00
|
|
|
" Escaping needs to be handled specially for CMD on Windows.
|
|
|
|
let l:json_string = has('win32')
|
|
|
|
\ ? '{"output":["x","y","z"]}'
|
|
|
|
\ : ale#Escape('{"output": ["x", "y", "z"]}')
|
|
|
|
|
2017-11-22 17:32:53 -05:00
|
|
|
return {
|
2017-11-22 18:45:51 -05:00
|
|
|
\ 'command': 'echo ' . l:json_string,
|
2017-11-22 17:32:53 -05:00
|
|
|
\ 'read_buffer': 0,
|
|
|
|
\ 'process_with': l:ProcessWith,
|
|
|
|
\}
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! JSONPostProcessor(buffer, output) abort
|
2017-11-22 18:45:51 -05:00
|
|
|
return json_decode(a:output[0]).output
|
2017-11-22 17:32:53 -05:00
|
|
|
endfunction
|
|
|
|
|
2017-05-18 08:21:14 -04:00
|
|
|
After:
|
|
|
|
Restore
|
|
|
|
unlet! g:ale_run_synchronously
|
2017-10-23 18:09:40 -04:00
|
|
|
unlet! g:ale_set_lists_synchronously
|
2017-05-18 08:21:14 -04:00
|
|
|
unlet! g:ale_emulate_job_failure
|
2017-05-20 11:00:05 -04:00
|
|
|
unlet! b:ale_fixers
|
2017-10-30 18:19:57 -04:00
|
|
|
unlet! b:ale_fix_on_save
|
2017-12-23 08:13:55 -05:00
|
|
|
augroup! VaderTest
|
2017-05-18 08:21:14 -04:00
|
|
|
delfunction AddCarets
|
|
|
|
delfunction AddDollars
|
|
|
|
delfunction DoNothing
|
|
|
|
delfunction CatLine
|
2017-06-06 18:13:53 -04:00
|
|
|
delfunction CatLineOneArg
|
2017-05-18 08:21:14 -04:00
|
|
|
delfunction ReplaceWithTempFile
|
2017-05-19 04:53:28 -04:00
|
|
|
delfunction RemoveLastLine
|
2017-06-06 18:13:53 -04:00
|
|
|
delfunction RemoveLastLineOneArg
|
2017-05-30 16:32:51 -04:00
|
|
|
delfunction TestCallback
|
2017-11-07 18:20:14 -05:00
|
|
|
delfunction FirstChainCallback
|
|
|
|
delfunction FirstChainCallbackSkipped
|
|
|
|
delfunction FirstChainCallbackSecondSkipped
|
|
|
|
delfunction SecondChainCallback
|
|
|
|
delfunction ThirdChainCallback
|
|
|
|
delfunction ChainWhereLastIsSkipped
|
|
|
|
delfunction ChainEndSkipped
|
2017-05-30 16:32:51 -04:00
|
|
|
delfunction SetUpLinters
|
2017-11-07 14:47:20 -05:00
|
|
|
delfunction GetLastMessage
|
2017-11-22 07:01:21 -05:00
|
|
|
delfunction IgnoredEmptyOutput
|
2017-11-22 08:01:13 -05:00
|
|
|
delfunction EchoLineNoPipe
|
2017-11-22 17:32:53 -05:00
|
|
|
delfunction FixWithJSONPostProcessing
|
|
|
|
delfunction JSONPostProcessor
|
2017-10-23 18:09:40 -04:00
|
|
|
|
|
|
|
call ale#test#RestoreDirectory()
|
|
|
|
|
2017-05-18 18:50:06 -04:00
|
|
|
call ale#fix#registry#ResetToDefaults()
|
2017-05-30 16:32:51 -04:00
|
|
|
call ale#linter#Reset()
|
|
|
|
|
2017-08-05 14:51:38 -04:00
|
|
|
setlocal buftype=nofile
|
|
|
|
|
2017-05-30 16:32:51 -04:00
|
|
|
if filereadable('fix_test_file')
|
|
|
|
call delete('fix_test_file')
|
|
|
|
endif
|
2017-05-18 08:21:14 -04:00
|
|
|
|
2017-07-10 08:40:22 -04:00
|
|
|
call setloclist(0, [])
|
|
|
|
|
2017-05-30 17:15:24 -04:00
|
|
|
let g:ale_fix_buffer_data = {}
|
|
|
|
|
2017-11-07 14:47:20 -05:00
|
|
|
" Clear the messages between tests.
|
|
|
|
echomsg ''
|
|
|
|
|
2017-05-18 08:21:14 -04:00
|
|
|
Given testft (A file with three lines):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
|
|
|
|
Execute(ALEFix should complain when there are no functions to call):
|
2017-11-07 14:47:20 -05:00
|
|
|
ALEFix
|
|
|
|
AssertEqual 'No fixers have been defined. Try :ALEFixSuggest', GetLastMessage()
|
2017-05-18 08:21:14 -04:00
|
|
|
|
|
|
|
Execute(ALEFix should apply simple functions):
|
|
|
|
let g:ale_fixers.testft = ['AddCarets']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(The first function should be used):
|
|
|
|
^a
|
|
|
|
^b
|
|
|
|
^c
|
|
|
|
|
|
|
|
Execute(ALEFix should apply simple functions in a chain):
|
|
|
|
let g:ale_fixers.testft = ['AddCarets', 'AddDollars']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(Both functions should be used):
|
|
|
|
$^a
|
|
|
|
$^b
|
|
|
|
$^c
|
|
|
|
|
|
|
|
Execute(ALEFix should allow 0 to be returned to skip functions):
|
|
|
|
let g:ale_fixers.testft = ['DoNothing', 'AddDollars']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(Only the second function should be applied):
|
|
|
|
$a
|
|
|
|
$b
|
|
|
|
$c
|
|
|
|
|
|
|
|
Execute(ALEFix should allow commands to be run):
|
2017-10-23 18:09:40 -04:00
|
|
|
if has('win32')
|
|
|
|
" Just skip this test on Windows, we can't run it.
|
|
|
|
call setline(1, ['a', 'b', 'c', 'd'])
|
|
|
|
else
|
|
|
|
let g:ale_fixers.testft = ['CatLine']
|
|
|
|
ALEFix
|
|
|
|
endif
|
2017-05-18 08:21:14 -04:00
|
|
|
|
|
|
|
Expect(An extra line should be added):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
d
|
|
|
|
|
|
|
|
Execute(ALEFix should allow temporary files to be read):
|
2017-10-23 18:09:40 -04:00
|
|
|
if has('win32')
|
|
|
|
" Just skip this test on Windows, we can't run it.
|
|
|
|
call setline(1, ['x'])
|
|
|
|
2,3d
|
|
|
|
else
|
|
|
|
let g:ale_fixers.testft = ['ReplaceWithTempFile']
|
|
|
|
ALEFix
|
|
|
|
endif
|
2017-05-18 08:21:14 -04:00
|
|
|
|
|
|
|
Expect(The line we wrote to the temporary file should be used here):
|
|
|
|
x
|
|
|
|
|
|
|
|
Execute(ALEFix should allow jobs and simple functions to be combined):
|
2017-10-23 18:09:40 -04:00
|
|
|
if has('win32')
|
|
|
|
" Just skip this test on Windows, we can't run it.
|
|
|
|
call setline(1, ['$x'])
|
|
|
|
2,3d
|
|
|
|
else
|
|
|
|
let g:ale_fixers.testft = ['ReplaceWithTempFile', 'AddDollars']
|
|
|
|
ALEFix
|
|
|
|
endif
|
2017-05-18 08:21:14 -04:00
|
|
|
|
|
|
|
Expect(The lines from the temporary file should be modified):
|
|
|
|
$x
|
|
|
|
|
2017-05-18 12:50:20 -04:00
|
|
|
Execute(ALEFix should send lines modified by functions to jobs):
|
2017-10-23 18:09:40 -04:00
|
|
|
if has('win32')
|
|
|
|
" Just skip this test on Windows, we can't run it.
|
|
|
|
call setline(1, ['$a', '$b', '$c', 'd'])
|
|
|
|
else
|
|
|
|
let g:ale_fixers.testft = ['AddDollars', 'CatLine']
|
|
|
|
ALEFix
|
|
|
|
endif
|
2017-05-18 12:50:20 -04:00
|
|
|
|
|
|
|
Expect(The lines should first be modified by the function, then the job):
|
|
|
|
$a
|
|
|
|
$b
|
|
|
|
$c
|
|
|
|
d
|
|
|
|
|
2017-05-18 08:21:14 -04:00
|
|
|
Execute(ALEFix should skip commands when jobs fail to run):
|
|
|
|
let g:ale_emulate_job_failure = 1
|
|
|
|
let g:ale_fixers.testft = ['CatLine', 'AddDollars']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(Only the second function should be applied):
|
|
|
|
$a
|
|
|
|
$b
|
|
|
|
$c
|
2017-05-18 12:26:17 -04:00
|
|
|
|
|
|
|
Execute(ALEFix should handle strings for selecting a single function):
|
|
|
|
let g:ale_fixers.testft = 'AddCarets'
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(The first function should be used):
|
|
|
|
^a
|
|
|
|
^b
|
|
|
|
^c
|
2017-05-18 18:50:06 -04:00
|
|
|
|
|
|
|
Execute(ALEFix should use functions from the registry):
|
|
|
|
call ale#fix#registry#Add('add_carets', 'AddCarets', [], 'Add some carets')
|
|
|
|
let g:ale_fixers.testft = ['add_carets']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(The registry function should be used):
|
|
|
|
^a
|
|
|
|
^b
|
|
|
|
^c
|
2017-05-19 04:53:28 -04:00
|
|
|
|
|
|
|
Execute(ALEFix should be able to remove the last line for files):
|
|
|
|
let g:ale_fixers.testft = ['RemoveLastLine']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(There should be only two lines):
|
|
|
|
a
|
|
|
|
b
|
2017-05-19 10:44:52 -04:00
|
|
|
|
|
|
|
Execute(ALEFix should accept funcrefs):
|
|
|
|
let g:ale_fixers.testft = [function('RemoveLastLine')]
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(There should be only two lines):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
|
|
|
|
Execute(ALEFix should accept lambdas):
|
|
|
|
if has('nvim')
|
|
|
|
" NeoVim 0.1.7 can't interpret lambdas correctly, so just set the lines
|
|
|
|
" to make the test pass.
|
|
|
|
call setline(1, ['a', 'b', 'c', 'd'])
|
|
|
|
else
|
|
|
|
let g:ale_fixers.testft = [{buffer, lines -> lines + ['d']}]
|
|
|
|
ALEFix
|
|
|
|
endif
|
|
|
|
|
|
|
|
Expect(There should be an extra line):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
d
|
2017-05-20 11:00:05 -04:00
|
|
|
|
|
|
|
Execute(ALEFix should user buffer-local fixer settings):
|
|
|
|
let g:ale_fixers.testft = ['AddCarets', 'AddDollars']
|
|
|
|
let b:ale_fixers = {'testft': ['RemoveLastLine']}
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(There should be only two lines):
|
|
|
|
a
|
|
|
|
b
|
2017-05-30 16:32:51 -04:00
|
|
|
|
2017-11-11 18:04:08 -05:00
|
|
|
Execute(ALEFix should allow Lists to be used for buffer-local fixer settings):
|
|
|
|
let g:ale_fixers.testft = ['AddCarets', 'AddDollars']
|
|
|
|
let b:ale_fixers = ['RemoveLastLine']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(There should be only two lines):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
|
2017-05-30 16:32:51 -04:00
|
|
|
Given testft (A file with three lines):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
|
|
|
|
Execute(ALEFix should save files on the save event):
|
|
|
|
let g:ale_fix_on_save = 1
|
|
|
|
let g:ale_lint_on_save = 1
|
|
|
|
let g:ale_enabled = 1
|
|
|
|
|
|
|
|
noautocmd silent file fix_test_file
|
2017-06-25 11:20:55 -04:00
|
|
|
call writefile(getline(1, '$'), 'fix_test_file')
|
2017-05-30 16:32:51 -04:00
|
|
|
|
|
|
|
let g:ale_fixers.testft = ['AddDollars']
|
|
|
|
|
2017-08-05 14:51:38 -04:00
|
|
|
" We have to set the buftype to empty so the file will be written.
|
|
|
|
setlocal buftype=
|
|
|
|
|
2017-05-30 16:32:51 -04:00
|
|
|
call SetUpLinters()
|
2017-07-31 19:03:24 -04:00
|
|
|
call ale#events#SaveEvent(bufnr(''))
|
2017-05-30 16:32:51 -04:00
|
|
|
|
|
|
|
" We should save the file.
|
|
|
|
AssertEqual ['$a', '$b', '$c'], readfile('fix_test_file')
|
|
|
|
Assert !&modified, 'The was marked as ''modified'''
|
|
|
|
|
2017-10-23 18:09:40 -04:00
|
|
|
if !has('win32')
|
|
|
|
" We should have run the linter.
|
|
|
|
AssertEqual [{
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'col': 1,
|
|
|
|
\ 'text': 'xxx',
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'pattern': '',
|
|
|
|
\ 'valid': 1,
|
|
|
|
\}], getloclist(0)
|
|
|
|
endif
|
2017-05-30 16:32:51 -04:00
|
|
|
|
|
|
|
Expect(The buffer should be modified):
|
|
|
|
$a
|
|
|
|
$b
|
|
|
|
$c
|
|
|
|
|
|
|
|
Given testft (A file with three lines):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
|
|
|
|
Execute(ALEFix should still lint with no linters to be applied):
|
|
|
|
let g:ale_fix_on_save = 1
|
|
|
|
let g:ale_lint_on_save = 1
|
|
|
|
let g:ale_enabled = 1
|
|
|
|
|
|
|
|
noautocmd silent file fix_test_file
|
|
|
|
|
|
|
|
let g:ale_fixers.testft = []
|
|
|
|
|
|
|
|
call SetUpLinters()
|
2017-07-31 19:03:24 -04:00
|
|
|
call ale#events#SaveEvent(bufnr(''))
|
2017-05-30 16:32:51 -04:00
|
|
|
|
|
|
|
Assert !filereadable('fix_test_file'), 'The file should not have been saved'
|
|
|
|
|
2017-10-23 18:09:40 -04:00
|
|
|
if !has('win32')
|
|
|
|
" We have run the linter.
|
|
|
|
AssertEqual [{
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'col': 1,
|
|
|
|
\ 'text': 'xxx',
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'pattern': '',
|
|
|
|
\ 'valid': 1,
|
|
|
|
\}], getloclist(0)
|
|
|
|
endif
|
2017-07-10 08:40:22 -04:00
|
|
|
|
|
|
|
Expect(The buffer should be the same):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
|
|
|
|
Execute(ALEFix should still lint when nothing was fixed on save):
|
|
|
|
let g:ale_fix_on_save = 1
|
|
|
|
let g:ale_lint_on_save = 1
|
|
|
|
let g:ale_enabled = 1
|
|
|
|
|
|
|
|
noautocmd silent file fix_test_file
|
|
|
|
|
|
|
|
let g:ale_fixers.testft = ['DoNothing']
|
|
|
|
|
|
|
|
call SetUpLinters()
|
2017-07-31 19:03:24 -04:00
|
|
|
call ale#events#SaveEvent(bufnr(''))
|
2017-07-10 08:40:22 -04:00
|
|
|
|
|
|
|
Assert !filereadable('fix_test_file'), 'The file should not have been saved'
|
|
|
|
|
2017-10-23 18:09:40 -04:00
|
|
|
if !has('win32')
|
|
|
|
" We should have run the linter.
|
|
|
|
AssertEqual [{
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'col': 1,
|
|
|
|
\ 'text': 'xxx',
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'pattern': '',
|
|
|
|
\ 'valid': 1,
|
|
|
|
\}], getloclist(0)
|
|
|
|
endif
|
2017-05-30 16:32:51 -04:00
|
|
|
|
|
|
|
Expect(The buffer should be the same):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
2017-05-30 17:15:24 -04:00
|
|
|
|
|
|
|
Given testft (A file with three lines):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
|
|
|
|
Execute(ale#fix#InitBufferData() should set up the correct data):
|
|
|
|
noautocmd silent file fix_test_file
|
|
|
|
|
|
|
|
call ale#fix#InitBufferData(bufnr(''), 'save_file')
|
|
|
|
|
|
|
|
AssertEqual {
|
|
|
|
\ bufnr(''): {
|
|
|
|
\ 'temporary_directory_list': [],
|
|
|
|
\ 'vars': b:,
|
2017-12-19 13:23:09 -05:00
|
|
|
\ 'filename': ale#path#Simplify(getcwd() . '/fix_test_file'),
|
2017-05-30 17:15:24 -04:00
|
|
|
\ 'done': 0,
|
|
|
|
\ 'lines_before': ['a', 'b', 'c'],
|
|
|
|
\ 'should_save': 1,
|
|
|
|
\ },
|
|
|
|
\}, g:ale_fix_buffer_data
|
2017-06-06 18:13:53 -04:00
|
|
|
|
|
|
|
Execute(ALEFix simple functions should be able to accept one argument, the buffer):
|
|
|
|
let g:ale_fixers.testft = ['RemoveLastLineOneArg']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(There should be only two lines):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
|
2017-10-30 18:19:57 -04:00
|
|
|
Execute(b:ale_fix_on_save = 1 should override g:ale_fix_on_save = 0):
|
|
|
|
let g:ale_fix_on_save = 0
|
|
|
|
let b:ale_fix_on_save = 1
|
|
|
|
|
|
|
|
let g:ale_fixers.testft = ['RemoveLastLineOneArg']
|
|
|
|
call ale#events#SaveEvent(bufnr(''))
|
|
|
|
|
|
|
|
Expect(There should be only two lines):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
|
|
|
|
Execute(b:ale_fix_on_save = 0 should override g:ale_fix_on_save = 1):
|
|
|
|
let g:ale_fix_on_save = 1
|
|
|
|
let b:ale_fix_on_save = 0
|
|
|
|
|
|
|
|
let g:ale_fixers.testft = ['RemoveLastLineOneArg']
|
|
|
|
call ale#events#SaveEvent(bufnr(''))
|
|
|
|
|
|
|
|
Expect(The lines should be the same):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
|
2017-06-06 18:13:53 -04:00
|
|
|
Execute(ALEFix functions returning jobs should be able to accept one argument):
|
2017-10-23 18:09:40 -04:00
|
|
|
if has('win32')
|
|
|
|
" Just skip this test on Windows, we can't run it.
|
|
|
|
call setline(1, ['a', 'b', 'c', 'd'])
|
|
|
|
else
|
|
|
|
let g:ale_fixers.testft = ['CatLine']
|
|
|
|
ALEFix
|
|
|
|
endif
|
2017-06-06 18:13:53 -04:00
|
|
|
|
|
|
|
Expect(An extra line should be added):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
d
|
2017-11-07 14:47:20 -05:00
|
|
|
|
|
|
|
Execute(ALE should print a message telling you something isn't a valid fixer when you type some nonsense):
|
|
|
|
let g:ale_fixers.testft = ['CatLine', 'invalidname']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
AssertEqual 'There is no fixer named `invalidname`. Check :ALEFixSuggest', GetLastMessage()
|
2017-11-07 18:20:14 -05:00
|
|
|
|
2018-02-18 05:13:30 -05:00
|
|
|
Execute(ALE should complain about invalid fixers with minuses in the name):
|
|
|
|
let g:ale_fixers.testft = ['foo-bar']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
AssertEqual 'There is no fixer named `foo-bar`. Check :ALEFixSuggest', GetLastMessage()
|
|
|
|
|
|
|
|
Execute(ALE should tolerate valid fixers with minuses in the name):
|
|
|
|
let g:ale_fixers.testft = ['prettier-standard']
|
|
|
|
ALEFix
|
|
|
|
|
2017-11-07 18:20:14 -05:00
|
|
|
Execute(Test fixing with chained callbacks):
|
|
|
|
let g:ale_fixers.testft = ['FirstChainCallback']
|
|
|
|
ALEFix
|
|
|
|
|
2017-11-22 08:01:13 -05:00
|
|
|
" The buffer shouldn't be piped in for earlier commands in the chain.
|
|
|
|
AssertEqual
|
|
|
|
\ [
|
2017-12-20 07:20:38 -05:00
|
|
|
\ string(ale#job#PrepareCommand(bufnr(''), 'echo echoline')),
|
|
|
|
\ string(ale#job#PrepareCommand(bufnr(''), 'echo echoline')),
|
2017-11-22 08:01:13 -05:00
|
|
|
\ ],
|
|
|
|
\ map(ale#history#Get(bufnr(''))[-2:-1], 'string(v:val.command)')
|
|
|
|
|
2017-11-07 18:20:14 -05:00
|
|
|
Expect(The echoed line should be added):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
echoline
|
|
|
|
|
|
|
|
Execute(Test fixing with chained callback where the first command is skipped):
|
|
|
|
let g:ale_fixers.testft = ['FirstChainCallbackSkipped']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(The default line should be added):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
emptydefault
|
|
|
|
|
|
|
|
Execute(Test fixing with chained callback where the second command is skipped):
|
|
|
|
let g:ale_fixers.testft = ['FirstChainCallbackSecondSkipped']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(The default line should be added):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
thirddefault
|
|
|
|
|
|
|
|
Execute(Test fixing with chained callback where the final callback is skipped):
|
|
|
|
let g:ale_fixers.testft = ['ChainWhereLastIsSkipped']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(The lines should be the same):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
2017-11-22 07:01:21 -05:00
|
|
|
|
|
|
|
Execute(Empty output should be ignored):
|
|
|
|
let g:ale_fixers.testft = ['IgnoredEmptyOutput']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(The lines should be the same):
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
2017-11-22 08:01:13 -05:00
|
|
|
|
|
|
|
Execute(A temporary file shouldn't be piped into the command when disabled):
|
|
|
|
let g:ale_fixers.testft = ['EchoLineNoPipe']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
AssertEqual
|
2017-12-20 07:20:38 -05:00
|
|
|
\ string(ale#job#PrepareCommand(bufnr(''), 'echo new line')),
|
2017-11-22 08:01:13 -05:00
|
|
|
\ string(ale#history#Get(bufnr(''))[-1].command)
|
|
|
|
|
2017-11-22 09:06:37 -05:00
|
|
|
" Remove trailing whitespace for Windows.
|
|
|
|
if has('win32')
|
|
|
|
%s/[[:space:]]*$//g
|
|
|
|
endif
|
|
|
|
|
2017-11-22 08:01:13 -05:00
|
|
|
Expect(The new line should be used):
|
|
|
|
new line
|
2017-11-22 17:32:53 -05:00
|
|
|
|
|
|
|
Execute(Post-processing should work):
|
|
|
|
let g:ale_fixers.testft = ['FixWithJSONPostProcessing']
|
|
|
|
ALEFix
|
|
|
|
|
|
|
|
Expect(The lines in the JSON should be used):
|
|
|
|
x
|
|
|
|
y
|
|
|
|
z
|
2017-12-23 08:13:55 -05:00
|
|
|
|
|
|
|
Execute(ALEFix should apply autocmds):
|
|
|
|
let g:ale_fixers.testft = ['AddCarets']
|
|
|
|
ALEFix
|
|
|
|
AssertEqual g:pre_success, 1
|
|
|
|
AssertEqual g:post_success, 1
|