diff --git a/test/rust_tests.vim b/test/rust_tests.vim index d6402d85..6dc22773 100644 --- a/test/rust_tests.vim +++ b/test/rust_tests.vim @@ -18,20 +18,99 @@ def g:Test_LspGotoDef() :cd xrust_tests/src try silent! edit ./main.rs - sleep 600m + deletebufline('%', 1, '$') + g:WaitForServerFileLoad(0) var lines: list =<< trim END + fn main() { + } fn foo() { } fn bar() { foo(); } END - append('$', lines) + setline(1, lines) g:WaitForServerFileLoad(0) - cursor(7, 5) + cursor(6, 5) :LspGotoDefinition - assert_equal([4, 4], [line('.'), col('.')]) + 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 =<< 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 =<< 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 =<< 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