summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-20 19:02:56 +0100
committerw0rp <devw0rp@gmail.com>2017-05-20 19:02:56 +0100
commitbf8bf0668113a1c5a378f05050722967f88a273f (patch)
treece8125f33a5a2e082d5e8d68e8234445c7ca8331 /test
parent0d797c203f22e593a6d19d127a8d1f4f78d3d106 (diff)
parent74d879952cfa3a27b21869bdbfef909c793178bb (diff)
downloadale-bf8bf0668113a1c5a378f05050722967f88a273f.zip
Merge branch 'error-fixing'
Diffstat (limited to 'test')
-rw-r--r--test/test_ale_fix.vader187
-rw-r--r--test/test_ale_fix_suggest.vader75
-rw-r--r--test/test_ale_toggle.vader3
-rw-r--r--test/test_eslint_executable_detection.vader8
4 files changed, 268 insertions, 5 deletions
diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader
new file mode 100644
index 00000000..dfe79443
--- /dev/null
+++ b/test/test_ale_fix.vader
@@ -0,0 +1,187 @@
+Before:
+ Save g:ale_fixers, &shell, g:ale_enabled
+ let g:ale_enabled = 0
+ let g:ale_run_synchronously = 1
+ let g:ale_fixers = {
+ \ 'testft': [],
+ \}
+ let &shell = '/bin/bash'
+
+ 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
+
+ function ReplaceWithTempFile(buffer, lines) abort
+ return {'command': 'echo x > %t', 'read_temporary_file': 1}
+ endfunction
+
+ function RemoveLastLine(buffer, lines) abort
+ return ['a', 'b']
+ endfunction
+
+After:
+ Restore
+ unlet! g:ale_run_synchronously
+ unlet! g:ale_emulate_job_failure
+ unlet! b:ale_fixers
+ delfunction AddCarets
+ delfunction AddDollars
+ delfunction DoNothing
+ delfunction CatLine
+ delfunction ReplaceWithTempFile
+ delfunction RemoveLastLine
+ call ale#fix#registry#ResetToDefaults()
+
+Given testft (A file with three lines):
+ a
+ b
+ c
+
+Execute(ALEFix should complain when there are no functions to call):
+ AssertThrows ALEFix
+ AssertEqual 'Vim(echoerr):No fixers have been defined. Try :ALEFixSuggest', g:vader_exception
+
+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):
+ let g:ale_fixers.testft = ['CatLine']
+ ALEFix
+
+Expect(An extra line should be added):
+ a
+ b
+ c
+ d
+
+Execute(ALEFix should allow temporary files to be read):
+ let g:ale_fixers.testft = ['ReplaceWithTempFile']
+ ALEFix
+
+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):
+ let g:ale_fixers.testft = ['ReplaceWithTempFile', 'AddDollars']
+ ALEFix
+
+Expect(The lines from the temporary file should be modified):
+ $x
+
+Execute(ALEFix should send lines modified by functions to jobs):
+ let g:ale_fixers.testft = ['AddDollars', 'CatLine']
+ ALEFix
+
+Expect(The lines should first be modified by the function, then the job):
+ $a
+ $b
+ $c
+ d
+
+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
+
+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
+
+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
+
+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
+
+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
+
+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
diff --git a/test/test_ale_fix_suggest.vader b/test/test_ale_fix_suggest.vader
new file mode 100644
index 00000000..9a7aecbf
--- /dev/null
+++ b/test/test_ale_fix_suggest.vader
@@ -0,0 +1,75 @@
+Before:
+ call ale#fix#registry#Clear()
+
+ function GetSuggestions()
+ redir => l:output
+ silent ALEFixSuggest
+ redir END
+
+ return split(l:output, "\n")
+ endfunction
+
+After:
+ call ale#fix#registry#ResetToDefaults()
+ delfunction GetSuggestions
+
+Execute(ALEFixSuggest should return something sensible with no suggestions):
+ AssertEqual
+ \ [
+ \ 'There is nothing in the registry to suggest.',
+ \ ],
+ \ GetSuggestions()
+
+Execute(ALEFixSuggest output should be correct for only generic handlers):
+ call ale#fix#registry#Add('zed', 'XYZ', [], 'Zedify things.')
+ call ale#fix#registry#Add('alpha', 'XYZ', [], 'Alpha things.')
+
+ AssertEqual
+ \ [
+ \ 'Try the following generic fixers:',
+ \ '',
+ \ '''alpha'' - Alpha things.',
+ \ '''zed'' - Zedify things.',
+ \ '',
+ \ 'See :help ale-fix-configuration',
+ \ ],
+ \ GetSuggestions()
+
+Execute(ALEFixSuggest output should be correct for only filetype handlers):
+ let &filetype = 'testft2.testft'
+
+ call ale#fix#registry#Add('zed', 'XYZ', ['testft2'], 'Zedify things.')
+ call ale#fix#registry#Add('alpha', 'XYZ', ['testft'], 'Alpha things.')
+
+ AssertEqual
+ \ [
+ \ 'Try the following fixers appropriate for the filetype:',
+ \ '',
+ \ '''alpha'' - Alpha things.',
+ \ '''zed'' - Zedify things.',
+ \ '',
+ \ 'See :help ale-fix-configuration',
+ \ ],
+ \ GetSuggestions()
+
+Execute(ALEFixSuggest should suggest filetype and generic handlers):
+ let &filetype = 'testft2.testft'
+
+ call ale#fix#registry#Add('zed', 'XYZ', ['testft2'], 'Zedify things.')
+ call ale#fix#registry#Add('alpha', 'XYZ', ['testft'], 'Alpha things.')
+ call ale#fix#registry#Add('generic', 'XYZ', [], 'Generic things.')
+
+ AssertEqual
+ \ [
+ \ 'Try the following fixers appropriate for the filetype:',
+ \ '',
+ \ '''alpha'' - Alpha things.',
+ \ '''zed'' - Zedify things.',
+ \ '',
+ \ 'Try the following generic fixers:',
+ \ '',
+ \ '''generic'' - Generic things.',
+ \ '',
+ \ 'See :help ale-fix-configuration',
+ \ ],
+ \ GetSuggestions()
diff --git a/test/test_ale_toggle.vader b/test/test_ale_toggle.vader
index 5d27c864..3546ad71 100644
--- a/test/test_ale_toggle.vader
+++ b/test/test_ale_toggle.vader
@@ -11,6 +11,7 @@ Before:
\ 'valid': 1,
\}]
let g:expected_groups = [
+ \ 'ALEBufferFixGroup',
\ 'ALECleanupGroup',
\ 'ALECursorGroup',
\ 'ALEHighlightBufferGroup',
@@ -101,7 +102,7 @@ Execute(ALEToggle should reset everything and then run again):
AssertEqual [], getloclist(0)
AssertEqual [], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual [], getmatches()
- AssertEqual ['ALECleanupGroup', 'ALEHighlightBufferGroup'], ParseAuGroups()
+ AssertEqual ['ALEBufferFixGroup', 'ALECleanupGroup', 'ALEHighlightBufferGroup'], ParseAuGroups()
" Toggle ALE on, everything should be set up and run again.
ALEToggle
diff --git a/test/test_eslint_executable_detection.vader b/test/test_eslint_executable_detection.vader
index e963ae1c..03bb89e8 100644
--- a/test/test_eslint_executable_detection.vader
+++ b/test/test_eslint_executable_detection.vader
@@ -20,7 +20,7 @@ Execute(create-react-app directories should be detected correctly):
AssertEqual
\ g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js',
- \ ale_linters#javascript#eslint#GetExecutable(bufnr(''))
+ \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
@@ -31,7 +31,7 @@ Execute(use-global should override create-react-app detection):
AssertEqual
\ 'eslint_d',
- \ ale_linters#javascript#eslint#GetExecutable(bufnr(''))
+ \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
@@ -40,7 +40,7 @@ Execute(other app directories should be detected correctly):
AssertEqual
\ g:dir . '/eslint-test-files/node_modules/.bin/eslint',
- \ ale_linters#javascript#eslint#GetExecutable(bufnr(''))
+ \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q
@@ -51,6 +51,6 @@ Execute(use-global should override other app directories):
AssertEqual
\ 'eslint_d',
- \ ale_linters#javascript#eslint#GetExecutable(bufnr(''))
+ \ ale#handlers#eslint#GetExecutable(bufnr(''))
:q