mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Cleanup presentation tests
This commit is contained in:
parent
a095cdb879
commit
9f9b38bdb4
2 changed files with 59 additions and 146 deletions
|
@ -460,7 +460,7 @@ mod tests {
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::completion::{
|
use crate::completion::{
|
||||||
test_utils::{do_completion, do_completion_with_options},
|
test_utils::{check_edit, do_completion, do_completion_with_options},
|
||||||
CompletionConfig, CompletionItem, CompletionKind,
|
CompletionConfig, CompletionItem, CompletionKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -636,150 +636,59 @@ fn foo() {
|
||||||
#[test]
|
#[test]
|
||||||
fn inserts_parens_for_function_calls() {
|
fn inserts_parens_for_function_calls() {
|
||||||
mark::check!(inserts_parens_for_function_calls);
|
mark::check!(inserts_parens_for_function_calls);
|
||||||
assert_debug_snapshot!(
|
check_edit(
|
||||||
do_reference_completion(
|
"no_args",
|
||||||
r"
|
r#"
|
||||||
fn no_args() {}
|
fn no_args() {}
|
||||||
fn main() { no_<|> }
|
fn main() { no_<|> }
|
||||||
"
|
"#,
|
||||||
),
|
r#"
|
||||||
@r###"
|
fn no_args() {}
|
||||||
[
|
fn main() { no_args()$0 }
|
||||||
CompletionItem {
|
"#,
|
||||||
label: "main()",
|
|
||||||
source_range: 28..31,
|
|
||||||
delete: 28..31,
|
|
||||||
insert: "main()$0",
|
|
||||||
kind: Function,
|
|
||||||
lookup: "main",
|
|
||||||
detail: "fn main()",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "no_args()",
|
|
||||||
source_range: 28..31,
|
|
||||||
delete: 28..31,
|
|
||||||
insert: "no_args()$0",
|
|
||||||
kind: Function,
|
|
||||||
lookup: "no_args",
|
|
||||||
detail: "fn no_args()",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###
|
|
||||||
);
|
);
|
||||||
assert_debug_snapshot!(
|
check_edit(
|
||||||
do_reference_completion(
|
"with_args",
|
||||||
r"
|
r#"
|
||||||
fn with_args(x: i32, y: String) {}
|
fn with_args(x: i32, y: String) {}
|
||||||
fn main() { with_<|> }
|
fn main() { with_<|> }
|
||||||
"
|
"#,
|
||||||
),
|
r#"
|
||||||
@r###"
|
fn with_args(x: i32, y: String) {}
|
||||||
[
|
fn main() { with_args(${1:x}, ${2:y})$0 }
|
||||||
CompletionItem {
|
"#,
|
||||||
label: "main()",
|
|
||||||
source_range: 47..52,
|
|
||||||
delete: 47..52,
|
|
||||||
insert: "main()$0",
|
|
||||||
kind: Function,
|
|
||||||
lookup: "main",
|
|
||||||
detail: "fn main()",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "with_args(…)",
|
|
||||||
source_range: 47..52,
|
|
||||||
delete: 47..52,
|
|
||||||
insert: "with_args(${1:x}, ${2:y})$0",
|
|
||||||
kind: Function,
|
|
||||||
lookup: "with_args",
|
|
||||||
detail: "fn with_args(x: i32, y: String)",
|
|
||||||
trigger_call_info: true,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###
|
|
||||||
);
|
);
|
||||||
assert_debug_snapshot!(
|
check_edit(
|
||||||
do_reference_completion(
|
"foo",
|
||||||
r"
|
r#"
|
||||||
fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String) {}
|
struct S;
|
||||||
fn main() { with_<|> }
|
impl S {
|
||||||
"
|
|
||||||
),
|
|
||||||
@r###"
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "main()",
|
|
||||||
source_range: 77..82,
|
|
||||||
delete: 77..82,
|
|
||||||
insert: "main()$0",
|
|
||||||
kind: Function,
|
|
||||||
lookup: "main",
|
|
||||||
detail: "fn main()",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "with_ignored_args(…)",
|
|
||||||
source_range: 77..82,
|
|
||||||
delete: 77..82,
|
|
||||||
insert: "with_ignored_args(${1:foo}, ${2:bar}, ${3:ho_ge_})$0",
|
|
||||||
kind: Function,
|
|
||||||
lookup: "with_ignored_args",
|
|
||||||
detail: "fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String)",
|
|
||||||
trigger_call_info: true,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###
|
|
||||||
);
|
|
||||||
assert_debug_snapshot!(
|
|
||||||
do_reference_completion(
|
|
||||||
r"
|
|
||||||
struct S {}
|
|
||||||
impl S {
|
|
||||||
fn foo(&self) {}
|
fn foo(&self) {}
|
||||||
}
|
}
|
||||||
fn bar(s: &S) {
|
fn bar(s: &S) { s.f<|> }
|
||||||
s.f<|>
|
"#,
|
||||||
}
|
r#"
|
||||||
"
|
struct S;
|
||||||
),
|
impl S {
|
||||||
@r###"
|
fn foo(&self) {}
|
||||||
[
|
}
|
||||||
CompletionItem {
|
fn bar(s: &S) { s.foo()$0 }
|
||||||
label: "foo()",
|
"#,
|
||||||
source_range: 66..67,
|
|
||||||
delete: 66..67,
|
|
||||||
insert: "foo()$0",
|
|
||||||
kind: Method,
|
|
||||||
lookup: "foo",
|
|
||||||
detail: "fn foo(&self)",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###
|
|
||||||
);
|
);
|
||||||
assert_debug_snapshot!(
|
|
||||||
do_reference_completion(
|
|
||||||
r"
|
|
||||||
struct S {}
|
|
||||||
impl S {
|
|
||||||
fn foo_ignored_args(&self, _a: bool, b: i32) {}
|
|
||||||
}
|
}
|
||||||
fn bar(s: &S) {
|
|
||||||
s.f<|>
|
#[test]
|
||||||
}
|
fn strips_underscores_from_args() {
|
||||||
"
|
check_edit(
|
||||||
),
|
"foo",
|
||||||
@r###"
|
r#"
|
||||||
[
|
fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
|
||||||
CompletionItem {
|
fn main() { f<|> }
|
||||||
label: "foo_ignored_args(…)",
|
"#,
|
||||||
source_range: 97..98,
|
r#"
|
||||||
delete: 97..98,
|
fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
|
||||||
insert: "foo_ignored_args(${1:a}, ${2:b})$0",
|
fn main() { foo(${1:foo}, ${2:bar}, ${3:ho_ge_})$0 }
|
||||||
kind: Method,
|
"#,
|
||||||
lookup: "foo_ignored_args",
|
|
||||||
detail: "fn foo_ignored_args(&self, _a: bool, b: i32)",
|
|
||||||
trigger_call_info: true,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
"###
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
|
use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
|
||||||
use stdx::format_to;
|
use stdx::{format_to, trim_indent};
|
||||||
use test_utils::assert_eq_text;
|
use test_utils::assert_eq_text;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -57,14 +57,18 @@ pub(crate) fn completion_list_with_options(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||||
|
let ra_fixture_after = trim_indent(ra_fixture_after);
|
||||||
let (analysis, position) = analysis_and_position(ra_fixture_before);
|
let (analysis, position) = analysis_and_position(ra_fixture_before);
|
||||||
let completions: Vec<CompletionItem> =
|
let completions: Vec<CompletionItem> =
|
||||||
analysis.completions(&CompletionConfig::default(), position).unwrap().unwrap().into();
|
analysis.completions(&CompletionConfig::default(), position).unwrap().unwrap().into();
|
||||||
let (completion,) =
|
let (completion,) = completions
|
||||||
completions.into_iter().filter(|it| it.label() == what).collect_tuple().unwrap();
|
.iter()
|
||||||
|
.filter(|it| it.lookup() == what)
|
||||||
|
.collect_tuple()
|
||||||
|
.unwrap_or_else(|| panic!("can't find {:?} completion in {:#?}", what, completions));
|
||||||
let mut actual = analysis.file_text(position.file_id).unwrap().to_string();
|
let mut actual = analysis.file_text(position.file_id).unwrap().to_string();
|
||||||
completion.text_edit().apply(&mut actual);
|
completion.text_edit().apply(&mut actual);
|
||||||
assert_eq_text!(ra_fixture_after, &actual)
|
assert_eq_text!(&ra_fixture_after, &actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {
|
pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue