mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-15 16:57:06 +08:00
Add commands to run ALEFix, and some tests to cover functionality so far. Add a simple autopep8 function.
This commit is contained in:
109
test/test_ale_fix.vader
Normal file
109
test/test_ale_fix.vader
Normal file
@@ -0,0 +1,109 @@
|
||||
Before:
|
||||
Save g:ale_fixers, &shell
|
||||
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
|
||||
|
||||
After:
|
||||
Restore
|
||||
unlet! g:ale_run_synchronously
|
||||
unlet! g:ale_emulate_job_failure
|
||||
delfunction AddCarets
|
||||
delfunction AddDollars
|
||||
delfunction DoNothing
|
||||
delfunction CatLine
|
||||
delfunction ReplaceWithTempFile
|
||||
|
||||
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 for filetype: testft', 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 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user