diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lsp/test_lsp_command_formatting.vader | 1 | ||||
-rw-r--r-- | test/lsp/test_lsp_root_detection.vader | 63 | ||||
-rw-r--r-- | test/test_ale_info.vader | 1 | ||||
-rw-r--r-- | test/test_format_command.vader | 42 | ||||
-rw-r--r-- | test/test_sandbox_execution.vader | 2 | ||||
-rw-r--r-- | test/test_temporary_file_management.vader | 44 |
6 files changed, 119 insertions, 34 deletions
diff --git a/test/lsp/test_lsp_command_formatting.vader b/test/lsp/test_lsp_command_formatting.vader index 9721f37f..fcd4f78c 100644 --- a/test/lsp/test_lsp_command_formatting.vader +++ b/test/lsp/test_lsp_command_formatting.vader @@ -17,6 +17,7 @@ Execute(Command formatting should be applied correctly for LSP linters): call ale#lsp_linter#StartLSP( \ bufnr(''), \ { + \ 'name': 'linter', \ 'language_callback': {-> 'x'}, \ 'project_root_callback': {-> '/foo/bar'}, \ 'lsp': 'stdio', diff --git a/test/lsp/test_lsp_root_detection.vader b/test/lsp/test_lsp_root_detection.vader new file mode 100644 index 00000000..2575a62c --- /dev/null +++ b/test/lsp/test_lsp_root_detection.vader @@ -0,0 +1,63 @@ +Before: + call ale#assert#SetUpLinterTest('c', 'clangd') + + function! Hook1(buffer) + return 'abc123' + endfunction + +After: + let g:ale_lsp_root = {} + unlet! b:ale_lsp_root + delfunction Hook1 + + call ale#assert#TearDownLinterTest() + +Execute(The buffer-specific variable can be a string): + let b:ale_lsp_root = '/some/path' + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + +Execute(The buffer-specific variable can be a dictionary): + let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + +Execute(The buffer-specific variable can have funcrefs): + let b:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull 'abc123' + +Execute(The global variable can be a dictionary): + let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + +Execute(The global variable can have funcrefs): + let g:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull 'abc123' + +Execute(The buffer-specific variable overrides the global variable): + let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'} + let g:ale_lsp_root = {'clangd': '/not/this/path', 'golangserver': '/elsewhere'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + +Execute(The global variable is queried if the buffer-specific has no value): + let b:ale_lsp_root = {'golangserver': '/other/path'} + let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/elsewhere'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + + +Execute(The default hook value is acceptable): + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '' diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index 325c2aa8..29c19b8e 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -97,6 +97,7 @@ Before: \ 'let g:ale_list_vertical = 0', \ 'let g:ale_list_window_size = 10', \ 'let g:ale_loclist_msg_format = ''%code: %%s''', + \ 'let g:ale_lsp_root = {}', \ 'let g:ale_max_buffer_history_size = 20', \ 'let g:ale_max_signs = -1', \ 'let g:ale_maximum_file_size = 0', diff --git a/test/test_format_command.vader b/test/test_format_command.vader index 119c7138..15435326 100644 --- a/test/test_format_command.vader +++ b/test/test_format_command.vader @@ -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]) diff --git a/test/test_sandbox_execution.vader b/test/test_sandbox_execution.vader index 5a4974ba..cf994ce8 100644 --- a/test/test_sandbox_execution.vader +++ b/test/test_sandbox_execution.vader @@ -59,7 +59,7 @@ Execute(ALE shouldn't blow up if file cleanup happens in a sandbox): \ 'temporary_file_list': ['/tmp/foo'], \ 'temporary_directory_list': ['/tmp/bar'], \} - sandbox call ale#engine#RemoveManagedFiles(3) + sandbox call ale#command#RemoveManagedFiles(3) AssertEqual ['/tmp/foo'], g:ale_buffer_info[3].temporary_file_list AssertEqual ['/tmp/bar'], g:ale_buffer_info[3].temporary_directory_list diff --git a/test/test_temporary_file_management.vader b/test/test_temporary_file_management.vader index 4847706a..b25da7ac 100644 --- a/test/test_temporary_file_management.vader +++ b/test/test_temporary_file_management.vader @@ -13,21 +13,21 @@ Before: " We are registering a temporary file, so we should delete it. let g:filename = tempname() call writefile(['foo'], g:filename) - call ale#engine#ManageFile(a:buffer, g:filename) + call ale#command#ManageFile(a:buffer, g:filename) " We are registering this directory appropriately, so we should delete " the whole thing. let g:directory = tempname() call mkdir(g:directory) call writefile(['foo'], g:directory . '/bar') - call ale#engine#ManageDirectory(a:buffer, g:directory) + call ale#command#ManageDirectory(a:buffer, g:directory) " We are registering this directory as temporary file, so we " shouldn't delete it. let g:preserved_directory = tempname() call mkdir(g:preserved_directory) call writefile(['foo'], g:preserved_directory . '/bar') - call ale#engine#ManageFile(a:buffer, g:preserved_directory) + call ale#command#ManageFile(a:buffer, g:preserved_directory) return g:command endfunction @@ -42,6 +42,7 @@ Before: \ 'callback': 'TestCallback', \ 'command_callback': 'TestCommandCallback', \}) + call ale#command#ClearData() After: Restore @@ -58,6 +59,7 @@ After: delfunction TestCommandCallback delfunction TestCallback call ale#linter#Reset() + call ale#command#ClearData() Given foobar (Some imaginary filetype): foo @@ -95,11 +97,11 @@ Execute(ALE should delete managed files when the buffer is removed): Assert !isdirectory(g:directory), 'The temporary directory was not deleted' Assert isdirectory(g:preserved_directory), 'The tempoary directory was not kept' -Execute(ALE should create and delete directories for ale#engine#CreateDirectory()): +Execute(ALE should create and delete directories for ale#command#CreateDirectory()): call ale#engine#InitBufferInfo(bufnr('%')) - let b:dir = ale#engine#CreateDirectory(bufnr('%')) - let b:dir2 = ale#engine#CreateDirectory(bufnr('%')) + let b:dir = ale#command#CreateDirectory(bufnr('%')) + let b:dir2 = ale#command#CreateDirectory(bufnr('%')) Assert isdirectory(b:dir), 'The directory was not created' @@ -117,16 +119,26 @@ Execute(ALE should create and delete directories for ale#engine#CreateDirectory( Assert !isdirectory(b:dir), 'The directory was not deleted' Assert !isdirectory(b:dir2), 'The second directory was not deleted' -Execute(ale#engine#ManageFile should add the file even if the buffer info hasn't be set yet): - let g:ale_buffer_info = {} - call ale#engine#ManageFile(bufnr(''), '/foo/bar') +Execute(ale#command#ManageFile should add the file even if the buffer info hasn't be set yet): + call ale#command#ManageFile(bufnr(''), '/foo/bar') + AssertEqual - \ ['/foo/bar'], - \ g:ale_buffer_info[bufnr('')].temporary_file_list + \ { + \ bufnr(''): { + \ 'file_list': ['/foo/bar'], + \ 'directory_list': [], + \ }, + \ }, + \ ale#command#GetData() + +Execute(ale#command#ManageDirectory should add the directory even if the buffer info hasn't be set yet): + call ale#command#ManageDirectory(bufnr(''), '/foo/bar') -Execute(ale#engine#ManageDirectory should add the directory even if the buffer info hasn't be set yet): - let g:ale_buffer_info = {} - call ale#engine#ManageDirectory(bufnr(''), '/foo/bar') AssertEqual - \ ['/foo/bar'], - \ g:ale_buffer_info[bufnr('')].temporary_directory_list + \ { + \ bufnr(''): { + \ 'file_list': [], + \ 'directory_list': ['/foo/bar'], + \ }, + \ }, + \ ale#command#GetData() |