Skip to content

Commit

Permalink
add tests for fundamental types
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbarsky committed Feb 20, 2024
1 parent b67bbd1 commit a8d0dbd
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions crates/ide-completion/src/tests/flyimport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,129 @@ fn main() {
);
}

#[test]
fn trait_method_fuzzy_completion_aware_of_fundamental_boxes() {
let fixture = r#"
//- /fundamental.rs crate:fundamental
#[lang = "owned_box"]
#[fundamental]
pub struct Box<T>(T);
//- /foo.rs crate:foo
pub trait TestTrait {
fn some_method(&self);
}
//- /main.rs crate:main deps:foo,fundamental
struct TestStruct;
impl foo::TestTrait for fundamental::Box<TestStruct> {
fn some_method(&self) {}
}
fn main() {
let t = fundamental::Box(TestStruct);
t.$0
}
"#;

check(
fixture,
expect![[r#"
me some_method() (use foo::TestTrait) fn(&self)
"#]],
);

check_edit(
"some_method",
fixture,
r#"
use foo::TestTrait;
struct TestStruct;
impl foo::TestTrait for fundamental::Box<TestStruct> {
fn some_method(&self) {}
}
fn main() {
let t = fundamental::Box(TestStruct);
t.some_method()$0
}
"#,
);
}

#[test]
fn trait_method_fuzzy_completion_aware_of_fundamental_references() {
let fixture = r#"
//- /foo.rs crate:foo
pub trait TestTrait {
fn some_method(&self);
}
//- /main.rs crate:main deps:foo
struct TestStruct;
impl foo::TestTrait for &TestStruct {
fn some_method(&self) {}
}
fn main() {
let t = &TestStruct;
t.$0
}
"#;

check(
fixture,
expect![[r#"
me some_method() (use foo::TestTrait) fn(&self)
"#]],
);

check_edit(
"some_method",
fixture,
r#"
use foo::TestTrait;
struct TestStruct;
impl foo::TestTrait for &TestStruct {
fn some_method(&self) {}
}
fn main() {
let t = &TestStruct;
t.some_method()$0
}
"#,
);
}

#[test]
fn trait_method_fuzzy_completion_aware_of_unit_type() {
let fixture = r#"
//- minicore: from, sized
//- /main.rs crate:main
struct A;
impl Into<A> for () {
fn into(self) -> A {
A
}
}
fn main() {
let a = A;
a.$0
}
"#;

// note that this test passing is incorrect, as we'd expect that traits like
// `Into` to show up in the completions. for whatever reason, they still show
// up in in a rust-analyzer actually performing completions.
check(fixture, expect![[r#""#]]);
}

#[test]
fn trait_method_from_alias() {
let fixture = r#"
Expand Down

0 comments on commit a8d0dbd

Please sign in to comment.