summaryrefslogtreecommitdiff
path: root/test/fix
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-04-16 13:33:29 +0100
committerw0rp <devw0rp@gmail.com>2019-04-16 13:44:43 +0100
commit59f8c35a2fcfbc032de6115da0d5ab0bd38db035 (patch)
tree03548190046b673176f6a9d75a5b6581760ad958 /test/fix
parent24d277384ce98f4e38f0bfdf45a9cebbf940b213 (diff)
downloadale-59f8c35a2fcfbc032de6115da0d5ab0bd38db035.zip
Fix #1930 - Finish ale_fix_on_save_ignore
* Implementation had a bug * Documentation added * Tests added
Diffstat (limited to 'test/fix')
-rw-r--r--test/fix/test_ale_fix_ignore.vader110
1 files changed, 110 insertions, 0 deletions
diff --git a/test/fix/test_ale_fix_ignore.vader b/test/fix/test_ale_fix_ignore.vader
new file mode 100644
index 00000000..5eb9b9ab
--- /dev/null
+++ b/test/fix/test_ale_fix_ignore.vader
@@ -0,0 +1,110 @@
+Before:
+ Save g:ale_fixers
+ Save g:ale_fix_on_save
+ Save g:ale_fix_on_save_ignore
+
+ let g:ale_fix_on_save = 1
+ let g:ale_fixers = {'abc': ['a', 'b'], 'xyz': ['c', 'd']}
+ unlet! b:ale_fixers
+ unlet! b:ale_fix_on_save_ignore
+
+ function FixerA(buffer, lines) abort
+ return a:lines + ['a']
+ endfunction
+
+ function FixerB(buffer, lines) abort
+ return a:lines + ['b']
+ endfunction
+
+ function FixerC(buffer, lines) abort
+ return a:lines + ['c']
+ endfunction
+
+ function FixerD(buffer, lines) abort
+ return a:lines + ['d']
+ endfunction
+
+ set filetype=abc.xyz
+ let g:test_filename = tempname()
+ execute 'noautocmd silent file ' . fnameescape(g:test_filename)
+
+ call ale#fix#registry#Add('a', 'FixerA', ['abc'], '')
+ call ale#fix#registry#Add('b', 'FixerB', ['abc'], '')
+ call ale#fix#registry#Add('c', 'FixerC', ['xyz'], '')
+ call ale#fix#registry#Add('d', 'FixerD', ['xyz'], '')
+
+After:
+ Restore
+
+ if exists('g:test_filename') && filereadable(g:test_filename)
+ call delete(g:test_filename)
+ endif
+
+ unlet! b:ale_fixers
+ unlet! b:ale_fix_on_save_ignore
+ unlet! g:test_filename
+
+ delfunction FixerA
+ delfunction FixerB
+ delfunction FixerC
+ delfunction FixerD
+
+ call ale#fix#registry#ResetToDefaults()
+
+Given abc.xyz (An empty file):
+Execute(Ignoring with a filetype in a global Dictionary should work):
+ let g:ale_fix_on_save_ignore = {'abc': ['b'], 'xyz': ['c']}
+
+ call ale#events#SaveEvent(bufnr(''))
+
+ AssertEqual ['', 'a', 'd'], getline(1, '$')
+
+Execute(Ignoring with a filetype in a global List should work):
+ let g:ale_fix_on_save_ignore = ['b', 'c']
+
+ call ale#events#SaveEvent(bufnr(''))
+
+ AssertEqual ['', 'a', 'd'], getline(1, '$')
+
+Execute(Ignoring with a filetype in a local Dictionary should work):
+ let g:ale_fix_on_save_ignore = {'abc': ['b'], 'xyz': ['c']}
+ " The local Dictionary should entirely replace the global one.
+ let b:ale_fix_on_save_ignore = {'abc': ['b']}
+
+ call ale#events#SaveEvent(bufnr(''))
+
+ AssertEqual ['', 'a', 'c', 'd'], getline(1, '$')
+
+Execute(Ignoring with a filetype in a local List should work):
+ let g:ale_fix_on_save_ignore = {'abc': ['b'], 'xyz': ['c']}
+ " The local List should entirely replace the global Dictionary.
+ let b:ale_fix_on_save_ignore = ['b']
+
+ call ale#events#SaveEvent(bufnr(''))
+
+ AssertEqual ['', 'a', 'c', 'd'], getline(1, '$')
+
+Execute(Ignoring functions by reference with a Dictionary should work):
+ let g:ale_fixers = {
+ \ 'abc': [function('FixerA'), function('FixerB')],
+ \ 'xyz': [function('FixerC'), function('FixerD')],
+ \}
+ let b:ale_fix_on_save_ignore = {
+ \ 'abc': [function('FixerB')],
+ \ 'xyz': [function('FixerC')],
+ \}
+
+ call ale#events#SaveEvent(bufnr(''))
+
+ AssertEqual ['', 'a', 'd'], getline(1, '$')
+
+Execute(Ignoring functions by reference with a List should work):
+ let g:ale_fixers = {
+ \ 'abc': [function('FixerA'), function('FixerB')],
+ \ 'xyz': [function('FixerC'), function('FixerD')],
+ \}
+ let b:ale_fix_on_save_ignore = [function('FixerB'), function('FixerC')]
+
+ call ale#events#SaveEvent(bufnr(''))
+
+ AssertEqual ['', 'a', 'd'], getline(1, '$')