From: Andreas Louv Date: Thu, 30 Mar 2023 22:38:24 +0000 (+0200) Subject: Convert flaky TypeScript test to a clangd test X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=0b94001b14886d83b5fef48424506a41b6e06126;p=vim-lsp.git Convert flaky TypeScript test to a clangd test --- diff --git a/test/clangd_tests.vim b/test/clangd_tests.vim index 14bbc14..9148eb9 100644 --- a/test/clangd_tests.vim +++ b/test/clangd_tests.vim @@ -271,6 +271,86 @@ def g:Test_LspDiag() :%bw! enddef +# Test for multiple LSP diagnostics on the same line +def g:Test_LspDiag_Multi() + :silent! edit Xtest.c + sleep 200m + + var bnr: number = bufnr() + + setline(1, [ + 'int i = "a";', + 'int j = i;', + 'int y = 0;' + ]) + :redraw! + # TODO: Waiting count doesn't include Warning, Info, and Hint diags + g:WaitForServerFileLoad(2) + :LspDiagShow + var qfl: list> = getloclist(0) + assert_equal('quickfix', getwinvar(winnr('$'), '&buftype')) + assert_equal(bnr, qfl[0].bufnr) + assert_equal(3, qfl->len()) + assert_equal([1, 5, 'W'], [qfl[0].lnum, qfl[0].col, qfl[0].type]) + assert_equal([1, 9, 'E'], [qfl[1].lnum, qfl[1].col, qfl[1].type]) + assert_equal([2, 9, 'E'], [qfl[2].lnum, qfl[2].col, qfl[2].type]) + close + + :sleep 100m + cursor(2, 1) + assert_equal('', execute('LspDiagPrev')) + assert_equal([1, 9], [line('.'), col('.')]) + + assert_equal('', execute('LspDiagPrev')) + assert_equal([1, 5], [line('.'), col('.')]) + + var output = execute('LspDiagPrev')->split("\n") + assert_equal('Error: No more diagnostics found', output[0]) + + cursor(2, 1) + assert_equal('', execute('LspDiagFirst')) + assert_equal([1, 5], [line('.'), col('.')]) + assert_equal('', execute('LspDiagNext')) + assert_equal([1, 9], [line('.'), col('.')]) + popup_clear() + + # Test for :LspDiagHere on a line with multiple diagnostics + cursor(1, 1) + :LspDiagHere + assert_equal([1, 5], [line('.'), col('.')]) + var ids = popup_list() + assert_equal(1, ids->len()) + assert_match('Incompatible pointer to integer', getbufline(ids[0]->winbufnr(), 1, '$')[0]) + popup_clear() + cursor(1, 6) + :LspDiagHere + assert_equal([1, 9], [line('.'), col('.')]) + ids = popup_list() + assert_equal(1, ids->len()) + assert_match('Initializer element is not', getbufline(ids[0]->winbufnr(), 1, '$')[0]) + popup_clear() + + # Line without diagnostics + cursor(3, 1) + output = execute('LspDiagHere')->split("\n") + assert_equal('Error: No more diagnostics found on this line', output[0]) + + g:LspOptionsSet({showDiagInPopup: false}) + for i in range(1, 5) + cursor(1, i) + output = execute('LspDiagCurrent')->split('\n') + assert_match('Incompatible pointer to integer', output[0]) + endfor + for i in range(6, 12) + cursor(1, i) + output = execute('LspDiagCurrent')->split('\n') + assert_match('Initializer element is not ', output[0]) + endfor + g:LspOptionsSet({showDiagInPopup: true}) + + bw! +enddef + # Test for :LspCodeAction def g:Test_LspCodeAction() silent! edit Xtest.c diff --git a/test/tsserver_tests.vim b/test/tsserver_tests.vim index 68f7d5b..4130e93 100644 --- a/test/tsserver_tests.vim +++ b/test/tsserver_tests.vim @@ -13,90 +13,6 @@ var lspServers = [{ call LspAddServer(lspServers) echomsg systemlist($'{lspServers[0].path} --version') -# Test for LSP diagnostics -def g:Test_LspDiag() - :silent! edit Xtest.ts - sleep 200m - - var bnr: number = bufnr() - - # This tests that two diagnostics can be on the same line - var lines: list =<< trim END - export obj = { - foo: 1, - bar: 2, - baz; 3 - } - END - - setline(1, lines) - :redraw! - g:WaitForServerFileLoad(5) - :LspDiagShow - var qfl: list> = getloclist(0) - assert_equal('quickfix', getwinvar(winnr('$'), '&buftype')) - assert_equal(bnr, qfl[0].bufnr) - assert_equal(5, qfl->len()) - assert_equal([1, 1, 'E'], [qfl[0].lnum, qfl[0].col, qfl[0].type]) - assert_equal([1, 8, 'E'], [qfl[1].lnum, qfl[1].col, qfl[1].type]) - assert_equal([4, 3, 'E'], [qfl[2].lnum, qfl[2].col, qfl[2].type]) - close - - :sleep 100m - cursor(3, 1) - assert_equal('', execute('LspDiagPrev')) - assert_equal([1, 8], [line('.'), col('.')]) - - assert_equal('', execute('LspDiagPrev')) - assert_equal([1, 1], [line('.'), col('.')]) - - var output = execute('LspDiagPrev')->split("\n") - assert_equal('Error: No more diagnostics found', output[0]) - - cursor(5, 1) - assert_equal('', execute('LspDiagFirst')) - assert_equal([1, 1], [line('.'), col('.')]) - assert_equal('', execute('LspDiagNext')) - assert_equal([1, 8], [line('.'), col('.')]) - popup_clear() - - # Test for :LspDiagHere on a line with multiple diagnostics - cursor(4, 1) - :LspDiagHere - assert_equal([4, 3], [line('.'), col('.')]) - var ids = popup_list() - assert_equal(1, ids->len()) - assert_match('No value exists', getbufline(ids[0]->winbufnr(), 1, '$')[0]) - popup_clear() - cursor(4, 4) - :LspDiagHere - assert_equal([4, 6], [line('.'), col('.')]) - ids = popup_list() - assert_equal(1, ids->len()) - assert_match("',' expected.", getbufline(ids[0]->winbufnr(), 1, '$')[0]) - popup_clear() - - # Line without diagnostics - cursor(3, 1) - output = execute('LspDiagHere')->split("\n") - assert_equal('Error: No more diagnostics found on this line', output[0]) - - g:LspOptionsSet({showDiagInPopup: false}) - for i in range(1, 3) - cursor(4, i) - output = execute('LspDiagCurrent')->split('\n') - assert_match('No value exists in scope', output[0]) - endfor - for i in range(4, 8) - cursor(4, i) - output = execute('LspDiagCurrent')->split('\n') - assert_equal("',' expected.", output[0]) - endfor - g:LspOptionsSet({showDiagInPopup: true}) - - bw! -enddef - # Test for :LspGotoDefinition, :LspGotoDeclaration, etc. def g:Test_LspGoto() :silent! edit Xtest.ts