summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-07 23:20:14 +0000
committerw0rp <devw0rp@gmail.com>2017-11-07 23:20:14 +0000
commit1bf894f48c2169e18e5978c9347e40f186e425ab (patch)
tree9f61a99476233e80b70ab4f4efaecdb60f887d10 /test
parentd97924b6986216aea3eae68a3fdc27b9bde341bb (diff)
downloadale-1bf894f48c2169e18e5978c9347e40f186e425ab.zip
Fix #1086 - Implement command chaining for fixers
Diffstat (limited to 'test')
-rw-r--r--test/test_ale_fix.vader89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader
index fbf4755a..ffe3d93b 100644
--- a/test/test_ale_fix.vader
+++ b/test/test_ale_fix.vader
@@ -62,6 +62,49 @@ Before:
return [{'lnum': 1, 'col': 1, 'text': 'xxx'}]
endfunction
+ function! FirstChainCallback(buffer)
+ return {'command': 'echo echoline', 'chain_with': 'SecondChainCallback'}
+ endfunction
+
+ function! FirstChainCallbackSkipped(buffer)
+ return {'command': '', 'chain_with': 'SecondChainCallback'}
+ 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
+
function! SetUpLinters()
call ale#linter#Define('testft', {
\ 'name': 'testlinter',
@@ -97,6 +140,13 @@ After:
delfunction RemoveLastLine
delfunction RemoveLastLineOneArg
delfunction TestCallback
+ delfunction FirstChainCallback
+ delfunction FirstChainCallbackSkipped
+ delfunction FirstChainCallbackSecondSkipped
+ delfunction SecondChainCallback
+ delfunction ThirdChainCallback
+ delfunction ChainWhereLastIsSkipped
+ delfunction ChainEndSkipped
delfunction SetUpLinters
delfunction GetLastMessage
@@ -470,3 +520,42 @@ Execute(ALE should print a message telling you something isn't a valid fixer whe
ALEFix
AssertEqual 'There is no fixer named `invalidname`. Check :ALEFixSuggest', GetLastMessage()
+
+Execute(Test fixing with chained callbacks):
+ let g:ale_fixers.testft = ['FirstChainCallback']
+ ALEFix
+
+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