2017-02-11 18:14:18 +00:00
|
|
|
Before:
|
|
|
|
silent! cd /testplugin/test
|
2017-05-08 21:59:25 +00:00
|
|
|
silent file top/middle/bottom/dummy.txt
|
2017-02-11 18:14:18 +00:00
|
|
|
|
2017-10-23 00:26:31 +00:00
|
|
|
function! CheckTempFile(filename) abort
|
|
|
|
" Check every part of the temporary filename, except the random part.
|
|
|
|
AssertEqual fnamemodify(tempname(), ':h'), fnamemodify(a:filename, ':h:h')
|
|
|
|
AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t')
|
|
|
|
endfunction
|
|
|
|
|
2019-01-26 19:33:52 +00:00
|
|
|
runtime autoload/ale/command.vim
|
|
|
|
|
|
|
|
function! ale#command#CreateTempFile(buffer, temporary_file, input) abort
|
2019-01-12 18:34:17 +00:00
|
|
|
return !empty(a:temporary_file)
|
|
|
|
endfunction
|
|
|
|
|
2017-02-11 18:14:18 +00:00
|
|
|
After:
|
|
|
|
unlet! g:result
|
|
|
|
unlet! g:match
|
|
|
|
|
2017-10-23 00:26:31 +00:00
|
|
|
delfunction CheckTempFile
|
2019-01-26 19:33:52 +00:00
|
|
|
|
|
|
|
runtime autoload/ale/command.vim
|
2017-10-23 00:26:31 +00:00
|
|
|
|
2017-02-11 18:14:18 +00:00
|
|
|
Execute(FormatCommand should do nothing to basic command strings):
|
2019-01-12 18:34:17 +00:00
|
|
|
AssertEqual
|
|
|
|
\ ['', 'awesome-linter do something', 0],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, v:null, v:null, [])
|
2017-02-11 18:14:18 +00:00
|
|
|
|
|
|
|
Execute(FormatCommand should handle %%, and ignore other percents):
|
2019-01-12 18:34:17 +00:00
|
|
|
AssertEqual
|
|
|
|
\ ['', '% %%d %%f %x %', 0],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, v:null, v:null, [])
|
2017-02-11 18:14:18 +00:00
|
|
|
|
|
|
|
Execute(FormatCommand should convert %s to the current filename):
|
2017-10-23 00:26:31 +00:00
|
|
|
AssertEqual
|
|
|
|
\ [
|
|
|
|
\ '',
|
2019-01-12 18:34:17 +00:00
|
|
|
\ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p')),
|
|
|
|
\ 0,
|
2017-10-23 00:26:31 +00:00
|
|
|
\ ],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, v:null, v:null, [])
|
2017-02-11 18:14:18 +00:00
|
|
|
|
|
|
|
Execute(FormatCommand should convert %t to a new temporary filename):
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:null, v:null, [])
|
2017-10-23 00:26:31 +00:00
|
|
|
|
|
|
|
call CheckTempFile(g:result[0])
|
|
|
|
|
|
|
|
let g:match = matchlist(g:result[1], '\v^foo (.*) bar (.*)$')
|
2017-02-11 18:14:18 +00:00
|
|
|
|
|
|
|
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
|
|
|
|
" The first item of the result should be a temporary filename, and it should
|
|
|
|
" be the same as the escaped name in the command string.
|
2017-10-23 00:26:31 +00:00
|
|
|
AssertEqual ale#Escape(g:result[0]), g:match[1]
|
2017-02-11 18:14:18 +00:00
|
|
|
" The two temporary filenames formatted in should be the same.
|
|
|
|
AssertEqual g:match[1], g:match[2]
|
|
|
|
|
2019-01-26 19:33:52 +00:00
|
|
|
Execute(FormatCommand should not convert %t to a new temporary filename when the input is given as v:false):
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:false, v:null, [])
|
2019-01-26 19:33:52 +00:00
|
|
|
|
|
|
|
AssertEqual ['', 'foo %t bar %t', 0], g:result
|
|
|
|
|
2019-01-12 18:34:17 +00:00
|
|
|
Execute(FormatCommand should signal that files are created when temporary files are needed):
|
|
|
|
AssertEqual
|
|
|
|
\ 1,
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, v:null, v:null, [])[2]
|
2019-01-12 18:34:17 +00:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ 0,
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, v:null, v:null, [])[2]
|
2019-01-12 18:34:17 +00:00
|
|
|
|
2017-02-11 18:14:18 +00:00
|
|
|
Execute(FormatCommand should let you combine %s and %t):
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, v:null, v:null, [])
|
2017-10-23 00:26:31 +00:00
|
|
|
|
|
|
|
call CheckTempFile(g:result[0])
|
|
|
|
|
|
|
|
let g:match = matchlist(g:result[1], '\v^foo (.*) bar (.*)$')
|
2017-02-11 18:14:18 +00:00
|
|
|
|
|
|
|
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
|
|
|
|
" The first item of the result should be a temporary filename, and it should
|
|
|
|
" be the same as the escaped name in the command string.
|
2017-10-23 00:26:31 +00:00
|
|
|
AssertEqual ale#Escape(g:result[0]), g:match[1]
|
2017-02-11 18:14:18 +00:00
|
|
|
" The second item should be equal to the original filename.
|
2017-10-23 00:26:31 +00:00
|
|
|
AssertEqual ale#Escape(expand('%:p')), g:match[2]
|
2017-02-11 18:14:18 +00:00
|
|
|
|
2018-07-05 19:56:31 +00:00
|
|
|
Execute(FormatCommand should replace %e with the escaped executable):
|
|
|
|
if has('win32')
|
|
|
|
AssertEqual
|
2019-01-12 18:34:17 +00:00
|
|
|
\ ['', 'foo foo', 0],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null, v:null, [])
|
2018-07-05 19:56:31 +00:00
|
|
|
AssertEqual
|
2019-01-12 18:34:17 +00:00
|
|
|
\ ['', '"foo bar"', 0],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null, v:null, [])
|
2018-07-05 19:56:31 +00:00
|
|
|
AssertEqual
|
2019-01-12 18:34:17 +00:00
|
|
|
\ ['', '%e %e', 0],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null, v:null, [])
|
2018-07-05 19:56:31 +00:00
|
|
|
else
|
|
|
|
AssertEqual
|
2019-01-12 18:34:17 +00:00
|
|
|
\ ['', '''foo'' ''foo''', 0],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null, v:null, [])
|
2018-07-05 19:56:31 +00:00
|
|
|
AssertEqual
|
2019-01-12 18:34:17 +00:00
|
|
|
\ ['', '''foo bar''', 0],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null, v:null, [])
|
2018-07-05 19:56:31 +00:00
|
|
|
AssertEqual
|
2019-01-12 18:34:17 +00:00
|
|
|
\ ['', '%e %e', 0],
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null, v:null, [])
|
2018-07-05 19:56:31 +00:00
|
|
|
endif
|
|
|
|
|
2017-02-11 18:14:18 +00:00
|
|
|
Execute(EscapeCommandPart should escape all percent signs):
|
|
|
|
AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')
|
2017-05-17 10:17:49 +00:00
|
|
|
|
|
|
|
Execute(EscapeCommandPart should pipe in temporary files appropriately):
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, v:null, v:null, [])
|
2017-10-23 00:26:31 +00:00
|
|
|
|
|
|
|
call CheckTempFile(g:result[0])
|
|
|
|
|
|
|
|
let g:match = matchlist(g:result[1], '\v^foo bar \< (.*)$')
|
2017-05-17 10:17:49 +00:00
|
|
|
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
|
2017-10-23 00:26:31 +00:00
|
|
|
AssertEqual ale#Escape(g:result[0]), g:match[1]
|
2017-05-17 10:17:49 +00:00
|
|
|
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, v:null, v:null, [])
|
2017-10-23 00:26:31 +00:00
|
|
|
|
|
|
|
call CheckTempFile(g:result[0])
|
|
|
|
|
|
|
|
let g:match = matchlist(g:result[1], '\v^foo bar (.*)$')
|
2017-05-17 10:17:49 +00:00
|
|
|
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
|
2017-10-23 00:26:31 +00:00
|
|
|
AssertEqual ale#Escape(g:result[0]), g:match[1]
|
2020-08-23 18:55:42 +00:00
|
|
|
|
2020-08-24 08:33:07 +00:00
|
|
|
Execute(FormatCommand should apply filename modifiers to the current file):
|
|
|
|
AssertEqual
|
|
|
|
\ ale#Escape(expand('%:p:h'))
|
|
|
|
\ . ' ' . ale#Escape('dummy.txt')
|
|
|
|
\ . ' ' . ale#Escape(expand('%:p:h:t'))
|
|
|
|
\ . ' ' . ale#Escape('txt')
|
|
|
|
\ . ' ' . ale#Escape(expand('%:p:r')),
|
2021-03-01 20:11:10 +00:00
|
|
|
\ ale#command#FormatCommand(bufnr(''), '', '%s:h %s:t %s:h:t %s:e %s:r', 0, v:null, v:null, [])[1]
|
2020-08-24 08:33:07 +00:00
|
|
|
|
|
|
|
Execute(FormatCommand should apply filename modifiers to the temporary file):
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr(''), '', '%t:h %t:t %t:h:t %t:e %t:r', 0, v:null, v:null, [])
|
2020-08-24 08:33:07 +00:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ ale#Escape(fnamemodify(g:result[0], ':h'))
|
|
|
|
\ . ' ' . ale#Escape('dummy.txt')
|
|
|
|
\ . ' ' . ale#Escape(fnamemodify(g:result[0], ':h:t'))
|
|
|
|
\ . ' ' . ale#Escape('txt')
|
|
|
|
\ . ' ' . ale#Escape(fnamemodify(g:result[0], ':r')),
|
|
|
|
\ g:result[1]
|
|
|
|
|
2020-08-23 18:55:42 +00:00
|
|
|
Execute(FormatCommand should apply filename mappings the current file):
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', '%s', 0, v:null, v:null, [
|
2020-08-23 18:55:42 +00:00
|
|
|
\ [expand('%:p:h'), '/foo/bar'],
|
|
|
|
\])
|
|
|
|
|
|
|
|
Assert g:result[1] =~# '/foo/bar'
|
|
|
|
|
|
|
|
Execute(FormatCommand should apply filename mappings to temporary files):
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', '%t', 0, v:null, v:null, [
|
2020-08-23 18:55:42 +00:00
|
|
|
\ [fnamemodify(tempname(), ':h:h'), '/foo/bar']
|
|
|
|
\])
|
|
|
|
|
|
|
|
Assert g:result[1] =~# '/foo/bar'
|
2020-08-24 08:33:07 +00:00
|
|
|
|
|
|
|
Execute(FormatCommand should apply filename modifiers to mapped filenames):
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', '%s:h', 0, v:null, v:null, [
|
2020-08-24 08:33:07 +00:00
|
|
|
\ [expand('%:p:h'), '/foo/bar'],
|
|
|
|
\])
|
|
|
|
|
|
|
|
AssertEqual ale#Escape('/foo/bar'), g:result[1]
|
|
|
|
|
2021-03-01 20:11:10 +00:00
|
|
|
let g:result = ale#command#FormatCommand(bufnr('%'), '', '%t:h:h:h', 0, v:null, v:null, [
|
2020-08-24 08:33:07 +00:00
|
|
|
\ [fnamemodify(tempname(), ':h:h'), '/foo/bar']
|
|
|
|
\])
|
|
|
|
|
|
|
|
AssertEqual ale#Escape('/foo/bar'), g:result[1]
|
2021-03-01 20:11:10 +00:00
|
|
|
|
|
|
|
Execute(FormatCommand should apply regular cwd paths):
|
|
|
|
AssertEqual
|
|
|
|
\ 'cd ' . (has('unix') ? '' : '/d ') . ale#Escape('/foo /bar') . ' && abc',
|
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', 'abc', 0, v:null, '/foo /bar', [])[1]
|
|
|
|
\
|
2022-10-29 11:56:09 +00:00
|
|
|
Execute(FormatCommand should apply cwd substitution and formatting):
|
2021-03-01 20:11:10 +00:00
|
|
|
call ale#test#SetFilename('foo.txt')
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ 'cd ' . (has('unix') ? '' : '/d ') . ale#Escape(getcwd()) . ' && abc',
|
|
|
|
\ ale#command#FormatCommand(bufnr('%'), '', 'abc', 0, v:null, '%s:h', [])[1]
|