Skip to content

Commit f6bff05

Browse files
bors[bot]matklad
andauthored
Merge #5214
5214: Cleanup presentation tests r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents a095cdb + 9f9b38b commit f6bff05

File tree

2 files changed

+59
-146
lines changed

2 files changed

+59
-146
lines changed

crates/ra_ide/src/completion/presentation.rs

Lines changed: 51 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ mod tests {
460460
use test_utils::mark;
461461

462462
use crate::completion::{
463-
test_utils::{do_completion, do_completion_with_options},
463+
test_utils::{check_edit, do_completion, do_completion_with_options},
464464
CompletionConfig, CompletionItem, CompletionKind,
465465
};
466466

@@ -636,150 +636,59 @@ fn foo() {
636636
#[test]
637637
fn inserts_parens_for_function_calls() {
638638
mark::check!(inserts_parens_for_function_calls);
639-
assert_debug_snapshot!(
640-
do_reference_completion(
641-
r"
642-
fn no_args() {}
643-
fn main() { no_<|> }
644-
"
645-
),
646-
@r###"
647-
[
648-
CompletionItem {
649-
label: "main()",
650-
source_range: 28..31,
651-
delete: 28..31,
652-
insert: "main()$0",
653-
kind: Function,
654-
lookup: "main",
655-
detail: "fn main()",
656-
},
657-
CompletionItem {
658-
label: "no_args()",
659-
source_range: 28..31,
660-
delete: 28..31,
661-
insert: "no_args()$0",
662-
kind: Function,
663-
lookup: "no_args",
664-
detail: "fn no_args()",
665-
},
666-
]
667-
"###
668-
);
669-
assert_debug_snapshot!(
670-
do_reference_completion(
671-
r"
672-
fn with_args(x: i32, y: String) {}
673-
fn main() { with_<|> }
674-
"
675-
),
676-
@r###"
677-
[
678-
CompletionItem {
679-
label: "main()",
680-
source_range: 47..52,
681-
delete: 47..52,
682-
insert: "main()$0",
683-
kind: Function,
684-
lookup: "main",
685-
detail: "fn main()",
686-
},
687-
CompletionItem {
688-
label: "with_args(…)",
689-
source_range: 47..52,
690-
delete: 47..52,
691-
insert: "with_args(${1:x}, ${2:y})$0",
692-
kind: Function,
693-
lookup: "with_args",
694-
detail: "fn with_args(x: i32, y: String)",
695-
trigger_call_info: true,
696-
},
697-
]
698-
"###
639+
check_edit(
640+
"no_args",
641+
r#"
642+
fn no_args() {}
643+
fn main() { no_<|> }
644+
"#,
645+
r#"
646+
fn no_args() {}
647+
fn main() { no_args()$0 }
648+
"#,
699649
);
700-
assert_debug_snapshot!(
701-
do_reference_completion(
702-
r"
703-
fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String) {}
704-
fn main() { with_<|> }
705-
"
706-
),
707-
@r###"
708-
[
709-
CompletionItem {
710-
label: "main()",
711-
source_range: 77..82,
712-
delete: 77..82,
713-
insert: "main()$0",
714-
kind: Function,
715-
lookup: "main",
716-
detail: "fn main()",
717-
},
718-
CompletionItem {
719-
label: "with_ignored_args(…)",
720-
source_range: 77..82,
721-
delete: 77..82,
722-
insert: "with_ignored_args(${1:foo}, ${2:bar}, ${3:ho_ge_})$0",
723-
kind: Function,
724-
lookup: "with_ignored_args",
725-
detail: "fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String)",
726-
trigger_call_info: true,
727-
},
728-
]
729-
"###
650+
check_edit(
651+
"with_args",
652+
r#"
653+
fn with_args(x: i32, y: String) {}
654+
fn main() { with_<|> }
655+
"#,
656+
r#"
657+
fn with_args(x: i32, y: String) {}
658+
fn main() { with_args(${1:x}, ${2:y})$0 }
659+
"#,
730660
);
731-
assert_debug_snapshot!(
732-
do_reference_completion(
733-
r"
734-
struct S {}
735-
impl S {
736-
fn foo(&self) {}
737-
}
738-
fn bar(s: &S) {
739-
s.f<|>
740-
}
741-
"
742-
),
743-
@r###"
744-
[
745-
CompletionItem {
746-
label: "foo()",
747-
source_range: 66..67,
748-
delete: 66..67,
749-
insert: "foo()$0",
750-
kind: Method,
751-
lookup: "foo",
752-
detail: "fn foo(&self)",
753-
},
754-
]
755-
"###
661+
check_edit(
662+
"foo",
663+
r#"
664+
struct S;
665+
impl S {
666+
fn foo(&self) {}
667+
}
668+
fn bar(s: &S) { s.f<|> }
669+
"#,
670+
r#"
671+
struct S;
672+
impl S {
673+
fn foo(&self) {}
674+
}
675+
fn bar(s: &S) { s.foo()$0 }
676+
"#,
756677
);
757-
assert_debug_snapshot!(
758-
do_reference_completion(
759-
r"
760-
struct S {}
761-
impl S {
762-
fn foo_ignored_args(&self, _a: bool, b: i32) {}
763-
}
764-
fn bar(s: &S) {
765-
s.f<|>
766-
}
767-
"
768-
),
769-
@r###"
770-
[
771-
CompletionItem {
772-
label: "foo_ignored_args(…)",
773-
source_range: 97..98,
774-
delete: 97..98,
775-
insert: "foo_ignored_args(${1:a}, ${2:b})$0",
776-
kind: Method,
777-
lookup: "foo_ignored_args",
778-
detail: "fn foo_ignored_args(&self, _a: bool, b: i32)",
779-
trigger_call_info: true,
780-
},
781-
]
782-
"###
678+
}
679+
680+
#[test]
681+
fn strips_underscores_from_args() {
682+
check_edit(
683+
"foo",
684+
r#"
685+
fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
686+
fn main() { f<|> }
687+
"#,
688+
r#"
689+
fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
690+
fn main() { foo(${1:foo}, ${2:bar}, ${3:ho_ge_})$0 }
691+
"#,
783692
);
784693
}
785694

crates/ra_ide/src/completion/test_utils.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use hir::Semantics;
44
use itertools::Itertools;
55
use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
6-
use stdx::format_to;
6+
use stdx::{format_to, trim_indent};
77
use test_utils::assert_eq_text;
88

99
use crate::{
@@ -57,14 +57,18 @@ pub(crate) fn completion_list_with_options(
5757
}
5858

5959
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
60+
let ra_fixture_after = trim_indent(ra_fixture_after);
6061
let (analysis, position) = analysis_and_position(ra_fixture_before);
6162
let completions: Vec<CompletionItem> =
6263
analysis.completions(&CompletionConfig::default(), position).unwrap().unwrap().into();
63-
let (completion,) =
64-
completions.into_iter().filter(|it| it.label() == what).collect_tuple().unwrap();
64+
let (completion,) = completions
65+
.iter()
66+
.filter(|it| it.lookup() == what)
67+
.collect_tuple()
68+
.unwrap_or_else(|| panic!("can't find {:?} completion in {:#?}", what, completions));
6569
let mut actual = analysis.file_text(position.file_id).unwrap().to_string();
6670
completion.text_edit().apply(&mut actual);
67-
assert_eq_text!(ra_fixture_after, &actual)
71+
assert_eq_text!(&ra_fixture_after, &actual)
6872
}
6973

7074
pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {

0 commit comments

Comments
 (0)