Add method tests

This commit is contained in:
Kirill Bulatov 2020-02-10 00:30:00 +02:00
parent 24ab3e80ca
commit 2b9b16cb45

View file

@ -46,8 +46,8 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> {
let name_ref_to_import =
path_under_caret.syntax().descendants().find_map(ast::NameRef::cast)?;
if dbg!(source_analyzer
.resolve_path(ctx.db, &name_ref_to_import.syntax().ancestors().find_map(ast::Path::cast)?))
if source_analyzer
.resolve_path(ctx.db, &name_ref_to_import.syntax().ancestors().find_map(ast::Path::cast)?)
.is_some()
{
return None;
@ -307,4 +307,117 @@ mod tests {
",
);
}
#[test]
fn associated_struct_function() {
check_assist(
auto_import,
r"
mod test_mod {
pub struct TestStruct {}
impl TestStruct {
pub fn test_function() {}
}
}
fn main() {
TestStruct::test_function<|>
}
",
r"
use test_mod::TestStruct;
mod test_mod {
pub struct TestStruct {}
impl TestStruct {
pub fn test_function() {}
}
}
fn main() {
TestStruct::test_function<|>
}
",
);
}
#[test]
fn associated_trait_function() {
check_assist(
auto_import,
r"
mod test_mod {
pub trait TestTrait {
fn test_function();
}
pub struct TestStruct {}
impl TestTrait for TestStruct {
fn test_function() {}
}
}
fn main() {
test_mod::TestStruct::test_function<|>
}
",
r"
use test_mod::TestTrait;
mod test_mod {
pub trait TestTrait {
fn test_function();
}
pub struct TestStruct {}
impl TestTrait for TestStruct {
fn test_function() {}
}
}
fn main() {
test_mod::TestStruct::test_function<|>
}
",
);
}
#[test]
fn trait_method() {
check_assist(
auto_import,
r"
mod test_mod {
pub trait TestTrait {
fn test_method(&self);
}
pub struct TestStruct {}
impl TestTrait for TestStruct {
fn test_method(&self) {}
}
}
fn main() {
let test_struct = test_mod::TestStruct {};
test_struct.test_method<|>
}
",
r"
use test_mod::TestTrait;
mod test_mod {
pub trait TestTrait {
fn test_method(&self);
}
pub struct TestStruct {}
impl TestTrait for TestStruct {
fn test_method(&self) {}
}
}
fn main() {
let test_struct = test_mod::TestStruct {};
test_struct.test_method<|>
}
",
);
}
}