mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 13:14:29 +08:00
#2132 Unify temporary file management in command.vim
This commit is contained in:
@@ -8,7 +8,9 @@ Before:
|
||||
AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t')
|
||||
endfunction
|
||||
|
||||
function! TestCreateFunc(buffer, temporary_file) abort
|
||||
runtime autoload/ale/command.vim
|
||||
|
||||
function! ale#command#CreateTempFile(buffer, temporary_file, input) abort
|
||||
return !empty(a:temporary_file)
|
||||
endfunction
|
||||
|
||||
@@ -17,17 +19,18 @@ After:
|
||||
unlet! g:match
|
||||
|
||||
delfunction CheckTempFile
|
||||
delfunction TestCreateFunc
|
||||
|
||||
runtime autoload/ale/command.vim
|
||||
|
||||
Execute(FormatCommand should do nothing to basic command strings):
|
||||
AssertEqual
|
||||
\ ['', 'awesome-linter do something', 0],
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, v:null)
|
||||
|
||||
Execute(FormatCommand should handle %%, and ignore other percents):
|
||||
AssertEqual
|
||||
\ ['', '% %%d %%f %x %', 0],
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, v:null)
|
||||
|
||||
Execute(FormatCommand should convert %s to the current filename):
|
||||
AssertEqual
|
||||
@@ -36,10 +39,10 @@ Execute(FormatCommand should convert %s to the current filename):
|
||||
\ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p')),
|
||||
\ 0,
|
||||
\ ],
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, v:null)
|
||||
|
||||
Execute(FormatCommand should convert %t to a new temporary filename):
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, function('TestCreateFunc'))
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:null)
|
||||
|
||||
call CheckTempFile(g:result[0])
|
||||
|
||||
@@ -52,17 +55,22 @@ Execute(FormatCommand should convert %t to a new temporary filename):
|
||||
" The two temporary filenames formatted in should be the same.
|
||||
AssertEqual g:match[1], g:match[2]
|
||||
|
||||
Execute(FormatCommand should not convert %t to a new temporary filename when the input is given as v:false):
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:false)
|
||||
|
||||
AssertEqual ['', 'foo %t bar %t', 0], g:result
|
||||
|
||||
Execute(FormatCommand should signal that files are created when temporary files are needed):
|
||||
AssertEqual
|
||||
\ 1,
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, function('TestCreateFunc'))[2]
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, v:null)[2]
|
||||
|
||||
AssertEqual
|
||||
\ 0,
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, function('TestCreateFunc'))[2]
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, v:null)[2]
|
||||
|
||||
Execute(FormatCommand should let you combine %s and %t):
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, function('TestCreateFunc'))
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, v:null)
|
||||
|
||||
call CheckTempFile(g:result[0])
|
||||
|
||||
@@ -79,30 +87,30 @@ Execute(FormatCommand should replace %e with the escaped executable):
|
||||
if has('win32')
|
||||
AssertEqual
|
||||
\ ['', 'foo foo', 0],
|
||||
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null)
|
||||
AssertEqual
|
||||
\ ['', '"foo bar"', 0],
|
||||
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null)
|
||||
AssertEqual
|
||||
\ ['', '%e %e', 0],
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null)
|
||||
else
|
||||
AssertEqual
|
||||
\ ['', '''foo'' ''foo''', 0],
|
||||
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null)
|
||||
AssertEqual
|
||||
\ ['', '''foo bar''', 0],
|
||||
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null)
|
||||
AssertEqual
|
||||
\ ['', '%e %e', 0],
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc'))
|
||||
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null)
|
||||
endif
|
||||
|
||||
Execute(EscapeCommandPart should escape all percent signs):
|
||||
AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')
|
||||
|
||||
Execute(EscapeCommandPart should pipe in temporary files appropriately):
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, function('TestCreateFunc'))
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, v:null)
|
||||
|
||||
call CheckTempFile(g:result[0])
|
||||
|
||||
@@ -110,7 +118,7 @@ Execute(EscapeCommandPart should pipe in temporary files appropriately):
|
||||
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
|
||||
AssertEqual ale#Escape(g:result[0]), g:match[1]
|
||||
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, function('TestCreateFunc'))
|
||||
let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, v:null)
|
||||
|
||||
call CheckTempFile(g:result[0])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user