From 4e884e270a135cd18345170dbb73f7678163ac6d Mon Sep 17 00:00:00 2001 From: Andreas Louv Date: Sun, 2 Apr 2023 23:24:14 +0200 Subject: [PATCH] Convert another flaky typescript test to a go test The TypeScript tests are flaky as soon as they require diagnostics, as the diagnostic notification takes to long to be send by the server. --- test/gopls_tests.vim | 73 +++++++++++++++++++++++++++++++++--- test/tsserver_tests.vim | 82 ----------------------------------------- 2 files changed, 67 insertions(+), 88 deletions(-) diff --git a/test/gopls_tests.vim b/test/gopls_tests.vim index a574009..00fb2c2 100644 --- a/test/gopls_tests.vim +++ b/test/gopls_tests.vim @@ -12,6 +12,8 @@ call LspAddServer(lspServers) echomsg systemlist($'{lspServers[0].path} version') # Test for :LspGotoDefinition, :LspGotoDeclaration, etc. +# This test also tests that multiple locations will be +# shown in a list or popup def g:Test_LspGoto() :silent! edit Xtest.go sleep 200m @@ -19,11 +21,19 @@ def g:Test_LspGoto() var lines =<< trim END package main - func foo() { + type A/*goto implementation*/ interface { + Hello() } - func bar() { - foo(); + type B struct{} + + func (b *B) Hello() {} + + type C struct{} + + func (c *C) Hello() {} + + func main() { } END @@ -31,11 +41,62 @@ def g:Test_LspGoto() :redraw! g:WaitForServerFileLoad(0) - cursor(7, 1) + cursor(9, 10) :LspGotoDefinition - assert_equal([3, 6], [line('.'), col('.')]) + assert_equal([7, 6], [line('.'), col('.')]) exe "normal! \" - assert_equal([7, 1], [line('.'), col('.')]) + assert_equal([9, 10], [line('.'), col('.')]) + + cursor(9, 13) + :LspGotoImpl + assert_equal([4, 9], [line('.'), col('.')]) + + cursor(13, 13) + :LspGotoImpl + assert_equal([4, 9], [line('.'), col('.')]) + + # Two implementions needs to be shown in a location list + cursor(4, 9) + assert_equal('', execute('LspGotoImpl')) + sleep 200m + var loclist: list> = getloclist(0) + assert_equal('quickfix', getwinvar(winnr('$'), '&buftype')) + assert_equal(2, loclist->len()) + assert_equal(bufnr(), loclist[0].bufnr) + assert_equal([9, 13, ''], [loclist[0].lnum, loclist[0].col, loclist[0].type]) + assert_equal([13, 13, ''], [loclist[1].lnum, loclist[1].col, loclist[1].type]) + lclose + + # Two implementions needs to be shown in a quickfix list + g:LspOptionsSet({ useQuickfixForLocations: true }) + cursor(4, 9) + assert_equal('', execute('LspGotoImpl')) + sleep 200m + var qfl: list> = getqflist() + assert_equal('quickfix', getwinvar(winnr('$'), '&buftype')) + assert_equal(2, qfl->len()) + assert_equal(bufnr(), qfl[0].bufnr) + assert_equal([9, 13, ''], [qfl[0].lnum, qfl[0].col, qfl[0].type]) + assert_equal([13, 13, ''], [qfl[1].lnum, qfl[1].col, qfl[1].type]) + cclose + g:LspOptionsSet({ useQuickfixForLocations: false }) + + # Two implementions needs to be peeked in a popup + cursor(4, 9) + :LspPeekImpl + sleep 10m + var ids = popup_list() + assert_equal(2, ids->len()) + var filePopupAttrs = ids[0]->popup_getoptions() + var refPopupAttrs = ids[1]->popup_getoptions() + assert_match('Xtest', filePopupAttrs.title) + assert_match('Implementation', refPopupAttrs.title) + assert_equal(9, line('.', ids[0])) # current line in left panel + assert_equal(2, line('$', ids[1])) # last line in right panel + feedkeys("j\", 'xt') + assert_equal(13, line('.')) + assert_equal([], popup_list()) + popup_clear() bw! enddef diff --git a/test/tsserver_tests.vim b/test/tsserver_tests.vim index c286d86..99e2836 100644 --- a/test/tsserver_tests.vim +++ b/test/tsserver_tests.vim @@ -13,88 +13,6 @@ var lspServers = [{ call LspAddServer(lspServers) echomsg systemlist($'{lspServers[0].path} --version') -# Test for :LspGotoDefinition, :LspGotoDeclaration, etc. -def g:Test_LspGoto() - :silent! edit Xtest.ts - sleep 200m - - var lines: list = [ - 'function B(val: number): void;', - 'function B(val: string): void;', - 'function B(val: string | number) {', - ' console.log(val);', - ' return void 0;', - '}', - 'typeof B;', - 'B(1);', - 'B("1");' - ] - - setline(1, lines) - :redraw! - g:WaitForServerFileLoad(0) - - cursor(8, 1) - assert_equal('', execute('LspGotoDefinition')) - assert_equal([1, 10], [line('.'), col('.')]) - - cursor(9, 1) - assert_equal('', execute('LspGotoDefinition')) - assert_equal([2, 10], [line('.'), col('.')]) - - cursor(9, 1) - assert_equal('', execute('LspGotoDefinition')) - assert_equal([2, 10], [line('.'), col('.')]) - - cursor(7, 8) - assert_equal('', execute('LspGotoDefinition')) - sleep 200m - var loclist: list> = getloclist(0) - assert_equal('quickfix', getwinvar(winnr('$'), '&buftype')) - assert_equal(3, loclist->len()) - assert_equal(bufnr(), loclist[0].bufnr) - assert_equal([1, 10, ''], [loclist[0].lnum, loclist[0].col, loclist[0].type]) - assert_equal([2, 10, ''], [loclist[1].lnum, loclist[1].col, loclist[1].type]) - assert_equal([3, 10, ''], [loclist[2].lnum, loclist[2].col, loclist[2].type]) - lclose - - g:LspOptionsSet({ useQuickfixForLocations: true }) - cursor(7, 8) - assert_equal('', execute('LspGotoDefinition')) - sleep 200m - var qfl: list> = getqflist() - assert_equal('quickfix', getwinvar(winnr('$'), '&buftype')) - assert_equal(3, qfl->len()) - assert_equal(bufnr(), qfl[0].bufnr) - assert_equal([1, 10, ''], [qfl[0].lnum, qfl[0].col, qfl[0].type]) - assert_equal([2, 10, ''], [qfl[1].lnum, qfl[1].col, qfl[1].type]) - assert_equal([3, 10, ''], [qfl[2].lnum, qfl[2].col, qfl[2].type]) - cclose - g:LspOptionsSet({ useQuickfixForLocations: false }) - - # Opening the preview window with an unsaved buffer displays the "E37: No - # write since last change" error message. To disable this message, mark the - # buffer as not modified. - setlocal nomodified - cursor(7, 8) - :LspPeekDefinition - sleep 10m - var ids = popup_list() - assert_equal(2, ids->len()) - var filePopupAttrs = ids[0]->popup_getoptions() - var refPopupAttrs = ids[1]->popup_getoptions() - assert_match('Xtest', filePopupAttrs.title) - assert_match('Definitions', refPopupAttrs.title) - assert_equal(1, line('.', ids[0])) - assert_equal(3, line('$', ids[1])) - feedkeys("jj\", 'xt') - assert_equal(3, line('.')) - assert_equal([], popup_list()) - popup_clear() - - bw! -enddef - # Test for auto-completion. Make sure that only keywords that matches with the # keyword before the cursor are shown. # def g:Test_LspCompletion1() -- 2.48.1