mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Inline snapshots for all tests in presentation.rs
This commit is contained in:
parent
eb7d1b0fee
commit
460423e66c
7 changed files with 152 additions and 177 deletions
|
@ -183,32 +183,74 @@ impl Completions {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use test_utils::covers;
|
use test_utils::covers;
|
||||||
|
use crate::completion::{do_completion, CompletionItem, CompletionKind};
|
||||||
|
use insta::assert_debug_snapshot_matches;
|
||||||
|
|
||||||
use crate::completion::{check_completion, CompletionKind};
|
fn do_reference_completion(code: &str) -> Vec<CompletionItem> {
|
||||||
|
do_completion(code, CompletionKind::Reference)
|
||||||
fn check_reference_completion(code: &str, expected_completions: &str) {
|
|
||||||
check_completion(code, expected_completions, CompletionKind::Reference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn inserts_parens_for_function_calls() {
|
fn inserts_parens_for_function_calls() {
|
||||||
covers!(inserts_parens_for_function_calls);
|
covers!(inserts_parens_for_function_calls);
|
||||||
check_reference_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"inserts_parens_for_function_calls1",
|
do_reference_completion(
|
||||||
r"
|
r"
|
||||||
fn no_args() {}
|
fn no_args() {}
|
||||||
fn main() { no_<|> }
|
fn main() { no_<|> }
|
||||||
",
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
⋮[
|
||||||
|
⋮ CompletionItem {
|
||||||
|
⋮ label: "main",
|
||||||
|
⋮ source_range: [61; 64),
|
||||||
|
⋮ delete: [61; 64),
|
||||||
|
⋮ insert: "main()$0",
|
||||||
|
⋮ kind: Function,
|
||||||
|
⋮ detail: "fn main()",
|
||||||
|
⋮ },
|
||||||
|
⋮ CompletionItem {
|
||||||
|
⋮ label: "no_args",
|
||||||
|
⋮ source_range: [61; 64),
|
||||||
|
⋮ delete: [61; 64),
|
||||||
|
⋮ insert: "no_args()$0",
|
||||||
|
⋮ kind: Function,
|
||||||
|
⋮ detail: "fn no_args()",
|
||||||
|
⋮ },
|
||||||
|
⋮]
|
||||||
|
"###
|
||||||
);
|
);
|
||||||
check_reference_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"inserts_parens_for_function_calls2",
|
do_reference_completion(
|
||||||
r"
|
r"
|
||||||
fn with_args(x: i32, y: String) {}
|
fn with_args(x: i32, y: String) {}
|
||||||
fn main() { with_<|> }
|
fn main() { with_<|> }
|
||||||
",
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
⋮[
|
||||||
|
⋮ CompletionItem {
|
||||||
|
⋮ label: "main",
|
||||||
|
⋮ source_range: [80; 85),
|
||||||
|
⋮ delete: [80; 85),
|
||||||
|
⋮ insert: "main()$0",
|
||||||
|
⋮ kind: Function,
|
||||||
|
⋮ detail: "fn main()",
|
||||||
|
⋮ },
|
||||||
|
⋮ CompletionItem {
|
||||||
|
⋮ label: "with_args",
|
||||||
|
⋮ source_range: [80; 85),
|
||||||
|
⋮ delete: [80; 85),
|
||||||
|
⋮ insert: "with_args($0)",
|
||||||
|
⋮ kind: Function,
|
||||||
|
⋮ detail: "fn with_args(x: i32, y: String)",
|
||||||
|
⋮ },
|
||||||
|
⋮]
|
||||||
|
"###
|
||||||
);
|
);
|
||||||
check_reference_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"inserts_parens_for_function_calls3",
|
do_reference_completion(
|
||||||
r"
|
r"
|
||||||
struct S {}
|
struct S {}
|
||||||
impl S {
|
impl S {
|
||||||
|
@ -217,36 +259,79 @@ mod tests {
|
||||||
fn bar(s: &S) {
|
fn bar(s: &S) {
|
||||||
s.f<|>
|
s.f<|>
|
||||||
}
|
}
|
||||||
",
|
"
|
||||||
)
|
),
|
||||||
|
@r###"
|
||||||
|
⋮[
|
||||||
|
⋮ CompletionItem {
|
||||||
|
⋮ label: "foo",
|
||||||
|
⋮ source_range: [163; 164),
|
||||||
|
⋮ delete: [163; 164),
|
||||||
|
⋮ insert: "foo()$0",
|
||||||
|
⋮ kind: Method,
|
||||||
|
⋮ detail: "fn foo(&self)",
|
||||||
|
⋮ },
|
||||||
|
⋮]
|
||||||
|
"###
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dont_render_function_parens_in_use_item() {
|
fn dont_render_function_parens_in_use_item() {
|
||||||
check_reference_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"dont_render_function_parens_in_use_item",
|
do_reference_completion(
|
||||||
"
|
"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
mod m { pub fn foo() {} }
|
mod m { pub fn foo() {} }
|
||||||
use crate::m::f<|>;
|
use crate::m::f<|>;
|
||||||
",
|
"
|
||||||
)
|
),
|
||||||
|
@r#"[
|
||||||
|
CompletionItem {
|
||||||
|
label: "foo",
|
||||||
|
source_range: [40; 41),
|
||||||
|
delete: [40; 41),
|
||||||
|
insert: "foo",
|
||||||
|
kind: Function,
|
||||||
|
detail: "pub fn foo()",
|
||||||
|
},
|
||||||
|
]"#
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dont_render_function_parens_if_already_call() {
|
fn dont_render_function_parens_if_already_call() {
|
||||||
check_reference_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"dont_render_function_parens_if_already_call",
|
do_reference_completion(
|
||||||
"
|
"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
fn frobnicate() {}
|
fn frobnicate() {}
|
||||||
fn main() {
|
fn main() {
|
||||||
frob<|>();
|
frob<|>();
|
||||||
}
|
}
|
||||||
",
|
"
|
||||||
|
),
|
||||||
|
@r#"[
|
||||||
|
CompletionItem {
|
||||||
|
label: "frobnicate",
|
||||||
|
source_range: [35; 39),
|
||||||
|
delete: [35; 39),
|
||||||
|
insert: "frobnicate",
|
||||||
|
kind: Function,
|
||||||
|
detail: "fn frobnicate()",
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "main",
|
||||||
|
source_range: [35; 39),
|
||||||
|
delete: [35; 39),
|
||||||
|
insert: "main",
|
||||||
|
kind: Function,
|
||||||
|
detail: "fn main()",
|
||||||
|
},
|
||||||
|
]"#
|
||||||
);
|
);
|
||||||
check_reference_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"dont_render_function_parens_if_already_call_assoc_fn",
|
do_reference_completion(
|
||||||
"
|
"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
struct Foo {}
|
struct Foo {}
|
||||||
|
@ -254,8 +339,18 @@ mod tests {
|
||||||
fn main() {
|
fn main() {
|
||||||
Foo::ne<|>();
|
Foo::ne<|>();
|
||||||
}
|
}
|
||||||
",
|
"
|
||||||
)
|
),
|
||||||
|
@r#"[
|
||||||
|
CompletionItem {
|
||||||
|
label: "new",
|
||||||
|
source_range: [67; 69),
|
||||||
|
delete: [67; 69),
|
||||||
|
insert: "new",
|
||||||
|
kind: Function,
|
||||||
|
detail: "fn new() -> Foo",
|
||||||
|
},
|
||||||
|
]"#
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
---
|
|
||||||
created: "2019-05-23T22:23:35.158296242Z"
|
|
||||||
creator: insta@0.8.1
|
|
||||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
expression: kind_completions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "frobnicate",
|
|
||||||
source_range: [35; 39),
|
|
||||||
delete: [35; 39),
|
|
||||||
insert: "frobnicate",
|
|
||||||
kind: Function,
|
|
||||||
detail: "fn frobnicate()",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "main",
|
|
||||||
source_range: [35; 39),
|
|
||||||
delete: [35; 39),
|
|
||||||
insert: "main",
|
|
||||||
kind: Function,
|
|
||||||
detail: "fn main()",
|
|
||||||
},
|
|
||||||
]
|
|
|
@ -1,16 +0,0 @@
|
||||||
---
|
|
||||||
created: "2019-05-23T22:44:10.920136527Z"
|
|
||||||
creator: insta@0.8.1
|
|
||||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
expression: kind_completions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "new",
|
|
||||||
source_range: [67; 69),
|
|
||||||
delete: [67; 69),
|
|
||||||
insert: "new",
|
|
||||||
kind: Function,
|
|
||||||
detail: "fn new() -> Foo",
|
|
||||||
},
|
|
||||||
]
|
|
|
@ -1,16 +0,0 @@
|
||||||
---
|
|
||||||
created: "2019-05-23T22:23:35.154795561Z"
|
|
||||||
creator: insta@0.8.1
|
|
||||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
expression: kind_completions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "foo",
|
|
||||||
source_range: [40; 41),
|
|
||||||
delete: [40; 41),
|
|
||||||
insert: "foo",
|
|
||||||
kind: Function,
|
|
||||||
detail: "pub fn foo()",
|
|
||||||
},
|
|
||||||
]
|
|
|
@ -1,24 +0,0 @@
|
||||||
---
|
|
||||||
created: "2019-05-23T22:23:35.156115632Z"
|
|
||||||
creator: insta@0.8.1
|
|
||||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
expression: kind_completions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "main",
|
|
||||||
source_range: [53; 56),
|
|
||||||
delete: [53; 56),
|
|
||||||
insert: "main()$0",
|
|
||||||
kind: Function,
|
|
||||||
detail: "fn main()",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "no_args",
|
|
||||||
source_range: [53; 56),
|
|
||||||
delete: [53; 56),
|
|
||||||
insert: "no_args()$0",
|
|
||||||
kind: Function,
|
|
||||||
detail: "fn no_args()",
|
|
||||||
},
|
|
||||||
]
|
|
|
@ -1,24 +0,0 @@
|
||||||
---
|
|
||||||
created: "2019-05-23T22:44:10.916806744Z"
|
|
||||||
creator: insta@0.8.1
|
|
||||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
expression: kind_completions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "main",
|
|
||||||
source_range: [72; 77),
|
|
||||||
delete: [72; 77),
|
|
||||||
insert: "main()$0",
|
|
||||||
kind: Function,
|
|
||||||
detail: "fn main()",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "with_args",
|
|
||||||
source_range: [72; 77),
|
|
||||||
delete: [72; 77),
|
|
||||||
insert: "with_args($0)",
|
|
||||||
kind: Function,
|
|
||||||
detail: "fn with_args(x: i32, y: String)",
|
|
||||||
},
|
|
||||||
]
|
|
|
@ -1,16 +0,0 @@
|
||||||
---
|
|
||||||
created: "2019-05-23T22:44:40.543731193Z"
|
|
||||||
creator: insta@0.8.1
|
|
||||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
expression: kind_completions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "foo",
|
|
||||||
source_range: [139; 140),
|
|
||||||
delete: [139; 140),
|
|
||||||
insert: "foo()$0",
|
|
||||||
kind: Method,
|
|
||||||
detail: "fn foo(&self)",
|
|
||||||
},
|
|
||||||
]
|
|
Loading…
Add table
Add a link
Reference in a new issue