summaryrefslogtreecommitdiff
path: root/test/test_ale_fix.vader
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-30 21:32:51 +0100
committerw0rp <devw0rp@gmail.com>2017-05-30 21:32:51 +0100
commit6ec965c8e4618c14b05b05bd554b3fed9c1191e1 (patch)
tree1c2dcf20cbb3ee0d5c538b6d0760e5f0ea2fd755 /test/test_ale_fix.vader
parentbc317a7be5e5c9db85b59c6377f3a9b9f034535c (diff)
downloadale-6ec965c8e4618c14b05b05bd554b3fed9c1191e1.zip
#591 Support fixing files on save
Diffstat (limited to 'test/test_ale_fix.vader')
-rw-r--r--test/test_ale_fix.vader108
1 files changed, 107 insertions, 1 deletions
diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader
index dfe79443..b4ffc062 100644
--- a/test/test_ale_fix.vader
+++ b/test/test_ale_fix.vader
@@ -1,6 +1,15 @@
Before:
- Save g:ale_fixers, &shell, g:ale_enabled
+ 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
+
+ silent! cd /testplugin/test
+
let g:ale_enabled = 0
+ let g:ale_echo_cursor = 0
let g:ale_run_synchronously = 1
let g:ale_fixers = {
\ 'testft': [],
@@ -33,6 +42,19 @@ Before:
return ['a', 'b']
endfunction
+ function! TestCallback(buffer, output)
+ return [{'lnum': 1, 'col': 1, 'text': 'xxx'}]
+ endfunction
+
+ function! SetUpLinters()
+ call ale#linter#Define('testft', {
+ \ 'name': 'testlinter',
+ \ 'callback': 'TestCallback',
+ \ 'executable': 'true',
+ \ 'command': 'true',
+ \})
+ endfunction
+
After:
Restore
unlet! g:ale_run_synchronously
@@ -44,7 +66,14 @@ After:
delfunction CatLine
delfunction ReplaceWithTempFile
delfunction RemoveLastLine
+ delfunction TestCallback
+ delfunction SetUpLinters
call ale#fix#registry#ResetToDefaults()
+ call ale#linter#Reset()
+
+ if filereadable('fix_test_file')
+ call delete('fix_test_file')
+ endif
Given testft (A file with three lines):
a
@@ -185,3 +214,80 @@ Execute(ALEFix should user buffer-local fixer settings):
Expect(There should be only two lines):
a
b
+
+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
+
+ let g:ale_fixers.testft = ['AddDollars']
+
+ call SetUpLinters()
+ call ale#events#SaveEvent()
+
+ " We should save the file.
+ Assert filereadable('fix_test_file'), 'The file cannot be read'
+ AssertEqual ['$a', '$b', '$c'], readfile('fix_test_file')
+ Assert !&modified, 'The was marked as ''modified'''
+
+ " 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)
+
+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()
+ call ale#events#SaveEvent()
+
+ Assert !filereadable('fix_test_file'), 'The file should not have been saved'
+
+ " 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)
+
+Expect(The buffer should be the same):
+ a
+ b
+ c