diff options
author | w0rp <devw0rp@gmail.com> | 2019-01-12 18:34:17 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2019-01-12 18:34:26 +0000 |
commit | c0b2090fbbc7a72dcf4963bf4d72cb6fc0b61e1d (patch) | |
tree | 46dd47356cf5b6e28882e84a56f61ad98d618e9e /test | |
parent | 7f176390fc4c1b3c1a7be484e0a84c4eb8f896e3 (diff) | |
download | ale-c0b2090fbbc7a72dcf4963bf4d72cb6fc0b61e1d.zip |
#2132 Move CreateTemporaryFileForJob calls into FormatCommand
Diffstat (limited to 'test')
-rw-r--r-- | test/test_format_command.vader | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/test/test_format_command.vader b/test/test_format_command.vader index 71285efa..119c7138 100644 --- a/test/test_format_command.vader +++ b/test/test_format_command.vader @@ -8,28 +8,38 @@ Before: AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t') endfunction + function! TestCreateFunc(buffer, temporary_file) abort + return !empty(a:temporary_file) + endfunction + After: unlet! g:result unlet! g:match delfunction CheckTempFile + delfunction TestCreateFunc Execute(FormatCommand should do nothing to basic command strings): - AssertEqual ['', 'awesome-linter do something'], ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0) + AssertEqual + \ ['', 'awesome-linter do something', 0], + \ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, function('TestCreateFunc')) Execute(FormatCommand should handle %%, and ignore other percents): - AssertEqual ['', '% %%d %%f %x %'], ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0) + AssertEqual + \ ['', '% %%d %%f %x %', 0], + \ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, function('TestCreateFunc')) Execute(FormatCommand should convert %s to the current filename): AssertEqual \ [ \ '', - \ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p')) + \ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p')), + \ 0, \ ], - \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0) + \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, function('TestCreateFunc')) Execute(FormatCommand should convert %t to a new temporary filename): - let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0) + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, function('TestCreateFunc')) call CheckTempFile(g:result[0]) @@ -42,8 +52,17 @@ 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 signal that files are created when temporary files are needed): + AssertEqual + \ 1, + \ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, function('TestCreateFunc'))[2] + + AssertEqual + \ 0, + \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, function('TestCreateFunc'))[2] + Execute(FormatCommand should let you combine %s and %t): - let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0) + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, function('TestCreateFunc')) call CheckTempFile(g:result[0]) @@ -59,31 +78,31 @@ Execute(FormatCommand should let you combine %s and %t): Execute(FormatCommand should replace %e with the escaped executable): if has('win32') AssertEqual - \ ['', 'foo foo'], - \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0) + \ ['', 'foo foo', 0], + \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc')) AssertEqual - \ ['', '"foo bar"'], - \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0) + \ ['', '"foo bar"', 0], + \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc')) AssertEqual - \ ['', '%e %e'], - \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0) + \ ['', '%e %e', 0], + \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc')) else AssertEqual - \ ['', '''foo'' ''foo'''], - \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0) + \ ['', '''foo'' ''foo''', 0], + \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc')) AssertEqual - \ ['', '''foo bar'''], - \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0) + \ ['', '''foo bar''', 0], + \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc')) AssertEqual - \ ['', '%e %e'], - \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0) + \ ['', '%e %e', 0], + \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc')) 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) + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, function('TestCreateFunc')) call CheckTempFile(g:result[0]) @@ -91,7 +110,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) + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, function('TestCreateFunc')) call CheckTempFile(g:result[0]) |