diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/command_callback/clangd_paths/compile_commands.json | 0 | ||||
-rw-r--r-- | test/command_callback/test_c_clangd_command_callbacks.vader | 32 | ||||
-rw-r--r-- | test/command_callback/test_haskell_cabal_ghc_command_callbacks.vader | 23 | ||||
-rw-r--r-- | test/completion/test_completion_events.vader | 12 | ||||
-rw-r--r-- | test/completion/test_lsp_completion_messages.vader | 89 | ||||
-rw-r--r-- | test/completion/test_lsp_completion_parsing.vader | 6 | ||||
-rw-r--r-- | test/fix/test_ale_fix.vader | 2 | ||||
-rw-r--r-- | test/lsp/test_did_save_event.vader | 6 | ||||
-rw-r--r-- | test/lsp/test_lsp_command_formatting.vader | 9 | ||||
-rw-r--r-- | test/lsp/test_lsp_connections.vader | 34 | ||||
-rw-r--r-- | test/lsp/test_other_initialize_message_handling.vader | 6 | ||||
-rw-r--r-- | test/test_ale_var.vader | 12 | ||||
-rw-r--r-- | test/test_find_references.vader | 33 | ||||
-rw-r--r-- | test/test_go_to_definition.vader | 47 |
14 files changed, 254 insertions, 57 deletions
diff --git a/test/command_callback/clangd_paths/compile_commands.json b/test/command_callback/clangd_paths/compile_commands.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/clangd_paths/compile_commands.json diff --git a/test/command_callback/test_c_clangd_command_callbacks.vader b/test/command_callback/test_c_clangd_command_callbacks.vader new file mode 100644 index 00000000..c8c10b67 --- /dev/null +++ b/test/command_callback/test_c_clangd_command_callbacks.vader @@ -0,0 +1,32 @@ +Before: + call ale#assert#SetUpLinterTest('c', 'clangd') + + Save &filetype + let &filetype = 'c' + +After: + call ale#assert#TearDownLinterTest() + +Execute(The language string should be correct): + AssertLSPLanguage 'c' + +Execute(The default executable should be correct): + AssertLinter 'clangd', ale#Escape('clangd') + +Execute(The project root should be detected correctly): + AssertLSPProject '' + + call ale#test#SetFilename('clangd_paths/dummy.c') + + AssertLSPProject ale#path#Simplify(g:dir . '/clangd_paths') + +Execute(The executable should be configurable): + let g:ale_c_clangd_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') + +Execute(The options should be configurable): + let b:ale_c_clangd_options = '-compile-commands-dir=foo' + + AssertLinter 'clangd', ale#Escape('clangd') . ' ' . b:ale_c_clangd_options + diff --git a/test/command_callback/test_haskell_cabal_ghc_command_callbacks.vader b/test/command_callback/test_haskell_cabal_ghc_command_callbacks.vader new file mode 100644 index 00000000..650aefa3 --- /dev/null +++ b/test/command_callback/test_haskell_cabal_ghc_command_callbacks.vader @@ -0,0 +1,23 @@ +Before: + Save g:ale_haskell_cabal_ghc_options + + unlet! g:ale_haskell_cabal_ghc_options + unlet! b:ale_haskell_cabal_ghc_options + + runtime ale_linters/haskell/cabal_ghc.vim + +After: + Restore + unlet! b:ale_haskell_cabal_ghc_options + call ale#linter#Reset() + +Execute(The options should be used in the command): + AssertEqual + \ 'cabal exec -- ghc -fno-code -v0 %t', + \ ale_linters#haskell#cabal_ghc#GetCommand(bufnr('')) + + let b:ale_haskell_cabal_ghc_options = 'foobar' + + AssertEqual + \ 'cabal exec -- ghc foobar %t', + \ ale_linters#haskell#cabal_ghc#GetCommand(bufnr('')) diff --git a/test/completion/test_completion_events.vader b/test/completion/test_completion_events.vader index f8cf268c..f3e05950 100644 --- a/test/completion/test_completion_events.vader +++ b/test/completion/test_completion_events.vader @@ -32,8 +32,16 @@ Before: endfunction let g:ale_completion_delay = 0 - call ale#completion#Queue() - sleep 1m + + " Run this check a few times, as it can fail randomly. + for g:i in range(has('nvim-0.3') || has('win32') ? 5 : 1) + call ale#completion#Queue() + sleep 1m + + if g:get_completions_called is a:expect_success + break + endif + endfor AssertEqual a:expect_success, g:get_completions_called endfunction diff --git a/test/completion/test_lsp_completion_messages.vader b/test/completion/test_lsp_completion_messages.vader index 00a174dc..ed0f358b 100644 --- a/test/completion/test_lsp_completion_messages.vader +++ b/test/completion/test_lsp_completion_messages.vader @@ -13,11 +13,11 @@ Before: runtime autoload/ale/lsp.vim let g:message_list = [] + let g:capability_checked = '' let g:Callback = '' + let g:wait_callback_list = [] - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -35,15 +35,28 @@ Before: return 'i' endfunction + function! ale#lsp#WaitForCapability(conn_id, project_root, capability, callback) abort + let g:capability_checked = a:capability + call add(g:wait_callback_list, a:callback) + endfunction + + function! ale#lsp#RegisterCallback(conn_id, callback) abort + let g:Callback = a:callback + endfunction + " Replace the Send function for LSP, so we can monitor calls to it. function! ale#lsp#Send(conn_id, message, ...) abort call add(g:message_list, a:message) + + return 1 endfunction After: Restore unlet! g:message_list + unlet! g:capability_checked + unlet! g:wait_callback_list unlet! g:Callback unlet! b:ale_old_omnifunc unlet! b:ale_old_completopt @@ -84,6 +97,13 @@ Execute(The right message should be sent for the initial tsserver request): call ale#completion#GetCompletions() + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual 1, len(g:wait_callback_list) + AssertEqual 'completion', g:capability_checked + call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])') + " We should send the right callback. AssertEqual \ 'function(''ale#completion#HandleTSServerResponse'')', @@ -96,9 +116,9 @@ Execute(The right message should be sent for the initial tsserver request): AssertEqual \ { \ 'line_length': 3, - \ 'conn_id': 0, + \ 'conn_id': 347, \ 'column': 3, - \ 'request_id': 0, + \ 'request_id': 1, \ 'line': 1, \ 'prefix': 'fo', \ }, @@ -164,6 +184,13 @@ Execute(The right message should be sent for the initial LSP request): call ale#completion#GetCompletions() + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual 1, len(g:wait_callback_list) + AssertEqual 'completion', g:capability_checked + call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])') + " We should send the right callback. AssertEqual \ 'function(''ale#completion#HandleLSPResponse'')', @@ -192,10 +219,58 @@ Execute(The right message should be sent for the initial LSP request): AssertEqual \ { \ 'line_length': 3, - \ 'conn_id': 0, + \ 'conn_id': 347, \ 'column': 3, - \ 'request_id': 0, + \ 'request_id': 1, \ 'line': 1, \ 'prefix': 'fo', + \ 'completion_filter': 'ale#completion#python#CompletionItemFilter', \ }, \ get(b:, 'ale_completion_info', {}) + +Execute(Two completion requests shouldn't be sent in a row): + call ale#linter#PreventLoading('python') + call ale#linter#Define('python', { + \ 'name': 'foo', + \ 'lsp': 'stdio', + \ 'executable': 'foo', + \ 'command': 'foo', + \ 'project_root_callback': {-> '/foo/bar'}, + \}) + call ale#linter#Define('python', { + \ 'name': 'bar', + \ 'lsp': 'stdio', + \ 'executable': 'foo', + \ 'command': 'foo', + \ 'project_root_callback': {-> '/foo/bar'}, + \}) + let b:ale_linters = ['foo', 'bar'] + + " The cursor position needs to match what was saved before. + call setpos('.', [bufnr(''), 1, 5, 0]) + + call ale#completion#GetCompletions() + + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual 2, len(g:wait_callback_list) + AssertEqual 'completion', g:capability_checked + call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])') + + " We should only send one completion message for two LSP servers. + AssertEqual + \ [ + \ [1, 'textDocument/didChange', { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(expand('%:p')), + \ 'version': g:ale_lsp_next_version_id - 1, + \ }, + \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}] + \ }], + \ [0, 'textDocument/completion', { + \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, + \ 'position': {'line': 0, 'character': 3}, + \ }], + \ ], + \ g:message_list diff --git a/test/completion/test_lsp_completion_parsing.vader b/test/completion/test_lsp_completion_parsing.vader index 736353e3..d5a45b54 100644 --- a/test/completion/test_lsp_completion_parsing.vader +++ b/test/completion/test_lsp_completion_parsing.vader @@ -430,10 +430,10 @@ Execute(Should handle Python completion results correctly): \ } \ }) -Execute(Should handle missing detail keys): +Execute(Should handle missing keys): AssertEqual \ [ - \ {'word': 'x', 'menu': '', 'info': 'y', 'kind': 'f', 'icase': 1}, + \ {'word': 'x', 'menu': '', 'info': '', 'kind': 'v', 'icase': 1}, \ ], \ ale#completion#ParseLSPCompletions({ \ 'jsonrpc': '2.0', @@ -443,8 +443,6 @@ Execute(Should handle missing detail keys): \ 'items': [ \ { \ 'label': 'x', - \ 'kind': 3, - \ 'documentation': 'y', \ }, \ ] \ } diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index 80eda4a0..14206d8d 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -552,8 +552,6 @@ Execute(ale#fix#InitBufferData() should set up the correct data): AssertEqual { \ bufnr(''): { \ 'temporary_directory_list': [], - \ 'vars': b:, - \ 'filename': ale#path#Simplify(getcwd() . '/fix_test_file'), \ 'done': 0, \ 'lines_before': ['a', 'b', 'c'], \ 'should_save': 1, diff --git a/test/lsp/test_did_save_event.vader b/test/lsp/test_did_save_event.vader index b696ee4b..428135fb 100644 --- a/test/lsp/test_did_save_event.vader +++ b/test/lsp/test_did_save_event.vader @@ -14,7 +14,6 @@ Before: let g:ale_lsp_next_message_id = 1 let g:ale_run_synchronously = 1 let g:message_list = [] - let g:Callback = '' function! LanguageCallback() abort return 'foobar' @@ -34,9 +33,7 @@ Before: \ }) let g:ale_linters = {'foobar': ['dummy_linter']} - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -59,7 +56,6 @@ After: unlet! b:ale_enabled unlet! b:ale_linters - unlet! g:Callback unlet! g:message_list delfunction LanguageCallback diff --git a/test/lsp/test_lsp_command_formatting.vader b/test/lsp/test_lsp_command_formatting.vader index f436397f..9d2c84ee 100644 --- a/test/lsp/test_lsp_command_formatting.vader +++ b/test/lsp/test_lsp_command_formatting.vader @@ -23,15 +23,14 @@ Execute(Command formatting should be applied correctly for LSP linters): \ 'executable': has('win32') ? 'cmd': 'true', \ 'command': '%e --foo', \ }, - \ {->0} \) if has('win32') AssertEqual - \ ['cmd', 'cmd /s/c "cmd --foo"', '/foo/bar'], - \ g:args[:2] + \ ['cmd', 'cmd /s/c "cmd --foo"', {}], + \ g:args else AssertEqual - \ ['true', [&shell, '-c', '''true'' --foo'], '/foo/bar'], - \ g:args[:2] + \ ['true', [&shell, '-c', '''true'' --foo'], {}], + \ g:args endif diff --git a/test/lsp/test_lsp_connections.vader b/test/lsp/test_lsp_connections.vader index 8651d801..ae64eadb 100644 --- a/test/lsp/test_lsp_connections.vader +++ b/test/lsp/test_lsp_connections.vader @@ -2,6 +2,10 @@ Before: let g:ale_lsp_next_message_id = 1 After: + if exists('b:conn') && has_key(b:conn, 'id') + call ale#lsp#RemoveConnectionWithID(b:conn.id) + endif + unlet! b:data unlet! b:conn @@ -223,17 +227,20 @@ Execute(ale#lsp#ReadMessageData() should handle a message with part of a second \ ) Execute(Projects with regular project roots should be registered correctly): - let b:conn = {'projects': {}} - - call ale#lsp#RegisterProject(b:conn, '/foo/bar') + let b:conn = ale#lsp#NewConnection({}) + call ale#lsp#RegisterProject(b:conn.id, '/foo/bar') AssertEqual \ { - \ 'projects': { - \ '/foo/bar': {'initialized': 0, 'message_queue': [], 'init_request_id': 0}, + \ '/foo/bar': { + \ 'root': '/foo/bar', + \ 'initialized': 0, + \ 'message_queue': [], + \ 'capabilities_queue': [], + \ 'init_request_id': 0, \ }, \ }, - \ b:conn + \ b:conn.projects Execute(Projects with regular project roots should be fetched correctly): let b:conn = { @@ -247,17 +254,20 @@ Execute(Projects with regular project roots should be fetched correctly): \ ale#lsp#GetProject(b:conn, '/foo/bar') Execute(Projects with empty project roots should be registered correctly): - let b:conn = {'projects': {}} - - call ale#lsp#RegisterProject(b:conn, '') + let b:conn = ale#lsp#NewConnection({}) + call ale#lsp#RegisterProject(b:conn.id, '') AssertEqual \ { - \ 'projects': { - \ '<<EMPTY>>': {'initialized': 1, 'message_queue': [], 'init_request_id': 0}, + \ '<<EMPTY>>': { + \ 'root': '', + \ 'initialized': 1, + \ 'message_queue': [], + \ 'capabilities_queue': [], + \ 'init_request_id': 0, \ }, \ }, - \ b:conn + \ b:conn.projects Execute(Projects with empty project roots should be fetched correctly): let b:conn = { diff --git a/test/lsp/test_other_initialize_message_handling.vader b/test/lsp/test_other_initialize_message_handling.vader index f9567ee0..45457979 100644 --- a/test/lsp/test_other_initialize_message_handling.vader +++ b/test/lsp/test_other_initialize_message_handling.vader @@ -3,6 +3,7 @@ Before: \ 'initialized': 0, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \} let b:conn = { @@ -34,6 +35,7 @@ Execute(publishDiagnostics messages with files inside project directories should \ 'initialized': 0, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -47,6 +49,7 @@ Execute(publishDiagnostics messages with files inside project directories should \ 'initialized': 1, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -60,6 +63,7 @@ Execute(Messages with no method and capabilities should initialize projects): \ 'initialized': 1, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -120,6 +124,7 @@ Execute(Capabilities should bet set up correctly): \ '/foo/bar': { \ 'initialized': 1, \ 'message_queue': [], + \ 'capabilities_queue': [], \ 'init_request_id': 3, \ }, \ }, @@ -170,6 +175,7 @@ Execute(Disabled capabilities should be recognised correctly): \ '/foo/bar': { \ 'initialized': 1, \ 'message_queue': [], + \ 'capabilities_queue': [], \ 'init_request_id': 3, \ }, \ }, diff --git a/test/test_ale_var.vader b/test/test_ale_var.vader index 5f42fe95..419a9983 100644 --- a/test/test_ale_var.vader +++ b/test/test_ale_var.vader @@ -5,8 +5,6 @@ After: unlet! g:ale_some_variable unlet! b:undefined_variable_name - let g:ale_fix_buffer_data = {} - Execute(ale#Var should return global variables): AssertEqual 'abc', ale#Var(bufnr(''), 'some_variable') @@ -24,13 +22,3 @@ Execute(ale#Var should throw exceptions for undefined variables): let b:undefined_variable_name = 'def' AssertThrows call ale#Var(bufnr(''), 'undefined_variable_name') - -Execute(ale#Var return variables from deleted buffers, saved for fixing things): - let g:ale_fix_buffer_data[1347347] = {'vars': {'ale_some_variable': 'def'}} - - AssertEqual 'def', ale#Var(1347347, 'some_variable') - -Execute(ale#Var should return the global variable for unknown variables): - let g:ale_fix_buffer_data = {} - - AssertEqual 'abc', ale#Var(1347347, 'some_variable') diff --git a/test/test_find_references.vader b/test/test_find_references.vader index 150e0471..ecced068 100644 --- a/test/test_find_references.vader +++ b/test/test_find_references.vader @@ -3,20 +3,20 @@ Before: call ale#test#SetFilename('dummy.txt') let g:old_filename = expand('%:p') - let g:Callback = 0 + let g:Callback = '' let g:expr_list = [] let g:message_list = [] let g:preview_called = 0 let g:item_list = [] + let g:capability_checked = '' + let g:WaitCallback = v:null runtime autoload/ale/linter.vim runtime autoload/ale/lsp.vim runtime autoload/ale/util.vim runtime autoload/ale/preview.vim - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -29,6 +29,15 @@ Before: \} endfunction + function! ale#lsp#WaitForCapability(conn_id, project_root, capability, callback) abort + let g:capability_checked = a:capability + let g:WaitCallback = a:callback + endfunction + + function! ale#lsp#RegisterCallback(conn_id, callback) abort + let g:Callback = a:callback + endfunction + function! ale#lsp#Send(conn_id, message, root) abort call add(g:message_list, a:message) @@ -50,6 +59,8 @@ After: call ale#test#RestoreDirectory() call ale#linter#Reset() + unlet! g:capability_checked + unlet! g:WaitCallback unlet! g:old_filename unlet! g:Callback unlet! g:message_list @@ -152,6 +163,13 @@ Execute(tsserver reference requests should be sent): ALEFindReferences + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'references', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#references#HandleTSServerResponse'')', \ string(g:Callback) @@ -226,6 +244,13 @@ Execute(LSP reference requests should be sent): ALEFindReferences + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'references', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#references#HandleLSPResponse'')', \ string(g:Callback) diff --git a/test/test_go_to_definition.vader b/test/test_go_to_definition.vader index 749f4d7e..7f0e3fcb 100644 --- a/test/test_go_to_definition.vader +++ b/test/test_go_to_definition.vader @@ -3,17 +3,17 @@ Before: call ale#test#SetFilename('dummy.txt') let g:old_filename = expand('%:p') - let g:Callback = 0 + let g:Callback = '' let g:message_list = [] let g:expr_list = [] + let g:capability_checked = '' + let g:WaitCallback = v:null runtime autoload/ale/linter.vim runtime autoload/ale/lsp.vim runtime autoload/ale/util.vim - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -26,6 +26,15 @@ Before: \} endfunction + function! ale#lsp#WaitForCapability(conn_id, project_root, capability, callback) abort + let g:capability_checked = a:capability + let g:WaitCallback = a:callback + endfunction + + function! ale#lsp#RegisterCallback(conn_id, callback) abort + let g:Callback = a:callback + endfunction + function! ale#lsp#Send(conn_id, message, root) abort call add(g:message_list, a:message) @@ -42,6 +51,8 @@ After: call ale#test#RestoreDirectory() call ale#linter#Reset() + unlet! g:capability_checked + unlet! g:WaitCallback unlet! g:old_filename unlet! g:Callback unlet! g:message_list @@ -137,6 +148,13 @@ Execute(tsserver completion requests should be sent): ALEGoToDefinition + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'definition', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#definition#HandleTSServerResponse'')', \ string(g:Callback) @@ -151,6 +169,13 @@ Execute(tsserver tab completion requests should be sent): ALEGoToDefinitionInTab + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'definition', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#definition#HandleTSServerResponse'')', \ string(g:Callback) @@ -276,6 +301,13 @@ Execute(LSP completion requests should be sent): ALEGoToDefinition + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'definition', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#definition#HandleLSPResponse'')', \ string(g:Callback) @@ -305,6 +337,13 @@ Execute(LSP tab completion requests should be sent): ALEGoToDefinitionInTab + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'definition', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#definition#HandleLSPResponse'')', \ string(g:Callback) |