diff options
author | Marc Coquand <marc@mccd.space> | 2024-06-30 17:20:44 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-06-30 17:20:44 -0500 |
commit | aeabdffa8870c2b90a32f53c1d0e5b63367a6e27 (patch) | |
tree | d3b8e3395cbfc5c9ba4f1dd28ff807f18d582b26 /vim/pack/downloads/opt/lsp/test/rust_tests.vim | |
parent | 97ce8456231b997135be6c5f1afaee08eff2cbb1 (diff) | |
download | rcm-aeabdffa8870c2b90a32f53c1d0e5b63367a6e27.tar.gz rcm-aeabdffa8870c2b90a32f53c1d0e5b63367a6e27.tar.bz2 rcm-aeabdffa8870c2b90a32f53c1d0e5b63367a6e27.zip |
Vim
Diffstat (limited to 'vim/pack/downloads/opt/lsp/test/rust_tests.vim')
-rw-r--r-- | vim/pack/downloads/opt/lsp/test/rust_tests.vim | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/vim/pack/downloads/opt/lsp/test/rust_tests.vim b/vim/pack/downloads/opt/lsp/test/rust_tests.vim new file mode 100644 index 0000000..6dc2277 --- /dev/null +++ b/vim/pack/downloads/opt/lsp/test/rust_tests.vim @@ -0,0 +1,137 @@ +vim9script +# Unit tests for LSP rust-analyzer client + +source common.vim +source term_util.vim +source screendump.vim + +var lspServers = [{ + filetype: ['rust'], + path: exepath('rust-analyzer'), + args: [] + }] +call LspAddServer(lspServers) +echomsg systemlist($'{lspServers[0].path} --version') + +def g:Test_LspGotoDef() + settagstack(0, {items: []}) + :cd xrust_tests/src + try + silent! edit ./main.rs + deletebufline('%', 1, '$') + g:WaitForServerFileLoad(0) + var lines: list<string> =<< trim END + fn main() { + } + fn foo() { + } + fn bar() { + foo(); + } + END + setline(1, lines) + g:WaitForServerFileLoad(0) + cursor(6, 5) + :LspGotoDefinition + assert_equal([3, 4], [line('.'), col('.')]) + :%bw! + finally + :cd ../.. + endtry +enddef + +# Test for :LspCodeAction creating a file in the current directory +def g:Test_LspCodeAction_CreateFile() + :cd xrust_tests/src + try + silent! edit ./main.rs + deletebufline('%', 1, '$') + g:WaitForServerFileLoad(0) + var lines: list<string> =<< trim END + mod foo; + fn main() { + } + END + setline(1, lines) + g:WaitForServerFileLoad(1) + cursor(1, 1) + :LspCodeAction 1 + g:WaitForServerFileLoad(0) + assert_true(filereadable('foo.rs')) + :%bw! + delete('foo.rs') + finally + :cd ../.. + endtry +enddef + +# Test for :LspCodeAction creating a file in a subdirectory +def g:Test_LspCodeAction_CreateFile_Subdir() + :cd xrust_tests/src + try + silent! edit ./main.rs + deletebufline('%', 1, '$') + g:WaitForServerFileLoad(0) + var lines: list<string> =<< trim END + mod baz; + fn main() { + } + END + setline(1, lines) + g:WaitForServerFileLoad(1) + cursor(1, 1) + :LspCodeAction 2 + g:WaitForServerFileLoad(0) + assert_true(filereadable('baz/mod.rs')) + :%bw! + delete('baz', 'rf') + finally + :cd ../.. + endtry +enddef + +# Test for :LspCodeAction renaming a file +def g:Test_LspCodeAction_RenameFile() + :cd xrust_tests/src + try + silent! edit ./main.rs + deletebufline('%', 1, '$') + g:WaitForServerFileLoad(0) + writefile([], 'foobar.rs') + var lines: list<string> =<< trim END + mod foobar; + fn main() { + } + END + setline(1, lines) + g:WaitForServerFileLoad(0) + cursor(1, 5) + :LspRename foobaz + g:WaitForServerFileLoad(0) + assert_true(filereadable('foobaz.rs')) + :%bw! + delete('foobaz.rs') + finally + :cd ../.. + endtry +enddef + +def g:Test_ZZZ_Cleanup() + delete('./xrust_tests', 'rf') +enddef + +# Start the rust-analyzer language server. Returns true on success and false +# on failure. +def g:StartLangServer(): bool + system('cargo new xrust_tests') + :cd xrust_tests/src + var status = false + try + status = g:StartLangServerWithFile('./main.rs') + finally + :cd ../.. + endtry + return status +enddef + +# vim: shiftwidth=2 softtabstop=2 noexpandtab |