mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Move rendering tests to the render module
This commit is contained in:
parent
15b16917fc
commit
97a504805d
6 changed files with 1163 additions and 1095 deletions
|
@ -81,3 +81,213 @@ impl<'a> FunctionRender<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use test_utils::mark;
|
||||
|
||||
use crate::{
|
||||
test_utils::{check_edit, check_edit_with_config},
|
||||
CompletionConfig,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn inserts_parens_for_function_calls() {
|
||||
mark::check!(inserts_parens_for_function_calls);
|
||||
check_edit(
|
||||
"no_args",
|
||||
r#"
|
||||
fn no_args() {}
|
||||
fn main() { no_<|> }
|
||||
"#,
|
||||
r#"
|
||||
fn no_args() {}
|
||||
fn main() { no_args()$0 }
|
||||
"#,
|
||||
);
|
||||
|
||||
check_edit(
|
||||
"with_args",
|
||||
r#"
|
||||
fn with_args(x: i32, y: String) {}
|
||||
fn main() { with_<|> }
|
||||
"#,
|
||||
r#"
|
||||
fn with_args(x: i32, y: String) {}
|
||||
fn main() { with_args(${1:x}, ${2:y})$0 }
|
||||
"#,
|
||||
);
|
||||
|
||||
check_edit(
|
||||
"foo",
|
||||
r#"
|
||||
struct S;
|
||||
impl S {
|
||||
fn foo(&self) {}
|
||||
}
|
||||
fn bar(s: &S) { s.f<|> }
|
||||
"#,
|
||||
r#"
|
||||
struct S;
|
||||
impl S {
|
||||
fn foo(&self) {}
|
||||
}
|
||||
fn bar(s: &S) { s.foo()$0 }
|
||||
"#,
|
||||
);
|
||||
|
||||
check_edit(
|
||||
"foo",
|
||||
r#"
|
||||
struct S {}
|
||||
impl S {
|
||||
fn foo(&self, x: i32) {}
|
||||
}
|
||||
fn bar(s: &S) {
|
||||
s.f<|>
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
struct S {}
|
||||
impl S {
|
||||
fn foo(&self, x: i32) {}
|
||||
}
|
||||
fn bar(s: &S) {
|
||||
s.foo(${1:x})$0
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suppress_arg_snippets() {
|
||||
mark::check!(suppress_arg_snippets);
|
||||
check_edit_with_config(
|
||||
CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() },
|
||||
"with_args",
|
||||
r#"
|
||||
fn with_args(x: i32, y: String) {}
|
||||
fn main() { with_<|> }
|
||||
"#,
|
||||
r#"
|
||||
fn with_args(x: i32, y: String) {}
|
||||
fn main() { with_args($0) }
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strips_underscores_from_args() {
|
||||
check_edit(
|
||||
"foo",
|
||||
r#"
|
||||
fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
|
||||
fn main() { f<|> }
|
||||
"#,
|
||||
r#"
|
||||
fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
|
||||
fn main() { foo(${1:foo}, ${2:bar}, ${3:ho_ge_})$0 }
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_ref_when_matching_local_in_scope() {
|
||||
check_edit(
|
||||
"ref_arg",
|
||||
r#"
|
||||
struct Foo {}
|
||||
fn ref_arg(x: &Foo) {}
|
||||
fn main() {
|
||||
let x = Foo {};
|
||||
ref_ar<|>
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
struct Foo {}
|
||||
fn ref_arg(x: &Foo) {}
|
||||
fn main() {
|
||||
let x = Foo {};
|
||||
ref_arg(${1:&x})$0
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_mut_ref_when_matching_local_in_scope() {
|
||||
check_edit(
|
||||
"ref_arg",
|
||||
r#"
|
||||
struct Foo {}
|
||||
fn ref_arg(x: &mut Foo) {}
|
||||
fn main() {
|
||||
let x = Foo {};
|
||||
ref_ar<|>
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
struct Foo {}
|
||||
fn ref_arg(x: &mut Foo) {}
|
||||
fn main() {
|
||||
let x = Foo {};
|
||||
ref_arg(${1:&mut x})$0
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_ref_when_matching_local_in_scope_for_method() {
|
||||
check_edit(
|
||||
"apply_foo",
|
||||
r#"
|
||||
struct Foo {}
|
||||
struct Bar {}
|
||||
impl Bar {
|
||||
fn apply_foo(&self, x: &Foo) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Foo {};
|
||||
let y = Bar {};
|
||||
y.<|>
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
struct Foo {}
|
||||
struct Bar {}
|
||||
impl Bar {
|
||||
fn apply_foo(&self, x: &Foo) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Foo {};
|
||||
let y = Bar {};
|
||||
y.apply_foo(${1:&x})$0
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trim_mut_keyword_in_func_completion() {
|
||||
check_edit(
|
||||
"take_mutably",
|
||||
r#"
|
||||
fn take_mutably(mut x: &i32) {}
|
||||
|
||||
fn main() {
|
||||
take_m<|>
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
fn take_mutably(mut x: &i32) {}
|
||||
|
||||
fn main() {
|
||||
take_mutably(${1:x})$0
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue