]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Convert flaky TypeScript test to a clangd test
authorAndreas Louv <andreas@louv.dk>
Thu, 30 Mar 2023 22:38:24 +0000 (00:38 +0200)
committerAndreas Louv <andreas@louv.dk>
Thu, 30 Mar 2023 22:55:28 +0000 (00:55 +0200)
test/clangd_tests.vim
test/tsserver_tests.vim

index 14bbc14ad3fef499522adeb2469d4cd71859090f..9148eb981a1b48f8ce10efb5ff05ae5d4fd1eeb6 100644 (file)
@@ -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<dict<any>> = 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
index 68f7d5bd036743b40dfb17c060fd493c2633a3a3..4130e9352d071cea02df4aadd8e1f019eb717d25 100644 (file)
@@ -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<string> =<< trim END
-    export obj = {
-      foo: 1,
-      bar: 2,
-      baz; 3
-    }
-  END
-
-  setline(1, lines)
-  :redraw!
-  g:WaitForServerFileLoad(5)
-  :LspDiagShow
-  var qfl: list<dict<any>> = 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