Skip to content

Commit

Permalink
Add LspCodeAction tests for creating and renaming files
Browse files Browse the repository at this point in the history
  • Loading branch information
yegappan committed Feb 11, 2024
1 parent 2d24447 commit 705a4b2
Showing 1 changed file with 83 additions and 4 deletions.
87 changes: 83 additions & 4 deletions test/rust_tests.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> =<< 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<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
Expand Down

0 comments on commit 705a4b2

Please sign in to comment.