ale/test/fixers/test_prettier_fixer_callback.vader

98 lines
3.1 KiB
Plaintext
Raw Normal View History

Before:
call ale#test#SetDirectory('/testplugin/test/fixers')
Save g:ale_javascript_prettier_executable
Save g:ale_javascript_prettier_options
" Use an invalid global executable, so we don't match it.
let g:ale_javascript_prettier_executable = 'xxxinvalid'
let g:ale_javascript_prettier_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd ..
silent cd command_callback
let g:dir = getcwd()
After:
let g:ale_has_override = {}
call ale#test#RestoreDirectory()
call ale#semver#ResetVersionCache()
Execute(The prettier callback should return the correct default values):
call ale#test#SetFilename('../prettier-test-files/testfile.js')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --write',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
Execute(The --config option should not be set automatically):
let g:ale_javascript_prettier_use_local_config = 1
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --write',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
Execute(The prettier callback should include custom prettier options):
let g:ale_javascript_prettier_options = '--no-semi'
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' %t'
\ . ' --no-semi'
\ . ' --write',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])
Execute(The version check should be correct):
call ale#test#SetFilename('../prettier-test-files/testfile.js')
AssertEqual
\ {
\ 'chain_with': 'ale#fixers#prettier#ApplyFixForVersion',
\ 'command': ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --version',
\ },
\ ale#fixers#prettier#Fix(bufnr(''))
Execute(--stdin-filepath should be used when prettier is new enough):
let g:ale_javascript_prettier_options = '--no-semi'
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
AssertEqual
\ {
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ . ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --no-semi'
\ . ' --stdin-filepath %s --stdin',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
Execute(The version number should be cached):
call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js')
" Call the second callback with the version output.
call ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0'])
" Call it again without the vesrion output. We should use the newer command.
AssertEqual
\ {
\ 'command': 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
\ . ale#Escape(g:ale_javascript_prettier_executable)
\ . ' --stdin-filepath %s --stdin',
\ },
\ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), [])