summaryrefslogtreecommitdiff
path: root/test/fix/test_ale_fix.vader
diff options
context:
space:
mode:
Diffstat (limited to 'test/fix/test_ale_fix.vader')
-rw-r--r--test/fix/test_ale_fix.vader149
1 files changed, 41 insertions, 108 deletions
diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader
index c3dd20e4..a51a5a53 100644
--- a/test/fix/test_ale_fix.vader
+++ b/test/fix/test_ale_fix.vader
@@ -5,18 +5,22 @@ Before:
Save g:ale_fix_on_save
Save g:ale_lint_on_save
Save g:ale_echo_cursor
+ Save g:ale_command_wrapper
+ Save g:ale_filename_mappings
silent! cd /testplugin/test/fix
unlet! b:ale_lint_on_save
let g:ale_enabled = 0
let g:ale_echo_cursor = 0
+ let g:ale_command_wrapper = ''
let g:ale_run_synchronously = 1
let g:ale_set_lists_synchronously = 1
let g:ale_fix_buffer_data = {}
let g:ale_fixers = {
\ 'testft': [],
\}
+ let g:ale_filename_mappings = {}
let g:pre_success = 0
let g:post_success = 0
@@ -70,6 +74,10 @@ Before:
return {'command': 'cat %t <(echo d)'}
endfunction
+ function EchoFilename(buffer, lines) abort
+ return {'command': 'echo %s'}
+ endfunction
+
function RemoveLastLine(buffer, lines) abort
return ['a', 'b']
endfunction
@@ -82,56 +90,6 @@ Before:
return [{'lnum': 1, 'col': 1, 'text': 'xxx'}]
endfunction
- function! FirstChainCallback(buffer)
- return {'command': 'echo echoline', 'chain_with': 'SecondChainCallback'}
- endfunction
-
- function! FirstChainCallbackSkipped(buffer)
- 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}
- 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
-
" echo will output a single blank line, and we should ingore it.
function! IgnoredEmptyOutput(buffer, output)
return {'command': has('win32') ? 'echo(' : 'echo'}
@@ -203,16 +161,10 @@ After:
delfunction CatLineDeferred
delfunction ReplaceWithTempFile
delfunction CatWithTempFile
+ delfunction EchoFilename
delfunction RemoveLastLine
delfunction RemoveLastLineOneArg
delfunction TestCallback
- delfunction FirstChainCallback
- delfunction FirstChainCallbackSkipped
- delfunction FirstChainCallbackSecondSkipped
- delfunction SecondChainCallback
- delfunction ThirdChainCallback
- delfunction ChainWhereLastIsSkipped
- delfunction ChainEndSkipped
delfunction SetUpLinters
delfunction GetLastMessage
delfunction IgnoredEmptyOutput
@@ -264,6 +216,25 @@ Expect(The first function should be used):
^b
^c
+Execute(Should apply filename mpapings):
+ " The command echos %s, and we'll map the current path so we can check
+ " that ALEFix applies filename mappings, end-to-end.
+ let g:ale_filename_mappings = {
+ \ 'echo_filename': [
+ \ [expand('%:p:h') . '/', '/some/fake/path/'],
+ \ ],
+ \}
+
+ call ale#fix#registry#Add('echo_filename', 'EchoFilename', [], 'echo filename')
+ let g:ale_fixers.testft = ['echo_filename']
+ ALEFix
+ call ale#test#FlushJobs()
+ " Remote trailing whitespace from the line.
+ call setline(1, substitute(getline(1), '[ \r]\+$', '', ''))
+
+Expect(The mapped filename should be printed):
+ /some/fake/path/test.txt
+
Execute(ALEFix should apply simple functions in a chain):
let g:ale_fixers.testft = ['AddCarets', 'Capitalize']
ALEFix
@@ -756,6 +727,19 @@ Expect(There should be only two lines):
a
b
+Execute(ALEFix should modify a buffer that is not modifiable, if it becomes modifiable later):
+ let g:ale_fixers.testft = ['RemoveLastLineOneArg']
+
+ set nomodifiable
+ ALEFix
+ call ale#test#FlushJobs()
+ set modifiable
+ call ale#fix#ApplyQueuedFixes(bufnr(''))
+
+Expect(There should be only two lines):
+ a
+ b
+
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
@@ -814,57 +798,6 @@ Execute(ALE should tolerate valid fixers with minuses in the name):
ALEFix
call ale#test#FlushJobs()
-Execute(Test fixing with chained callbacks):
- let g:ale_fixers.testft = ['FirstChainCallback']
- ALEFix
- call ale#test#FlushJobs()
-
- " The buffer shouldn't be piped in for earlier commands in the chain.
- AssertEqual
- \ [
- \ string(ale#job#PrepareCommand(bufnr(''), 'echo echoline')),
- \ string(ale#job#PrepareCommand(bufnr(''), 'echo echoline')),
- \ ],
- \ map(ale#history#Get(bufnr(''))[-2:-1], 'string(v:val.command)')
-
-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
- call ale#test#FlushJobs()
-
-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
- call ale#test#FlushJobs()
-
-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
- call ale#test#FlushJobs()
-
-Expect(The lines should be the same):
- a
- b
- c
-
Execute(Empty output should be ignored):
let g:ale_fixers.testft = ['IgnoredEmptyOutput']
ALEFix