Skip to content

Commit 1ee524b

Browse files
bors[bot]matklad
andauthored
Merge #5220
5220: Fix lookup in tests r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 9f754e0 + 9dacd23 commit 1ee524b

File tree

6 files changed

+141
-183
lines changed

6 files changed

+141
-183
lines changed

crates/ra_ide/src/completion/complete_fn_param.rs

Lines changed: 60 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -54,85 +54,81 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
5454

5555
#[cfg(test)]
5656
mod tests {
57-
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind};
58-
use insta::assert_debug_snapshot;
57+
use expect::{expect, Expect};
5958

60-
fn do_magic_completion(code: &str) -> Vec<CompletionItem> {
61-
do_completion(code, CompletionKind::Magic)
59+
use crate::completion::{test_utils::do_completion, CompletionKind};
60+
61+
fn check(ra_fixture: &str, expect: Expect) {
62+
let actual = do_completion(ra_fixture, CompletionKind::Magic);
63+
expect.assert_debug_eq(&actual);
6264
}
6365

6466
#[test]
6567
fn test_param_completion_last_param() {
66-
assert_debug_snapshot!(
67-
do_magic_completion(
68-
r"
69-
fn foo(file_id: FileId) {}
70-
fn bar(file_id: FileId) {}
71-
fn baz(file<|>) {}
72-
",
73-
),
74-
@r###"
75-
[
76-
CompletionItem {
77-
label: "file_id: FileId",
78-
source_range: 61..65,
79-
delete: 61..65,
80-
insert: "file_id: FileId",
81-
lookup: "file_id",
82-
},
83-
]
84-
"###
68+
check(
69+
r#"
70+
fn foo(file_id: FileId) {}
71+
fn bar(file_id: FileId) {}
72+
fn baz(file<|>) {}
73+
"#,
74+
expect![[r#"
75+
[
76+
CompletionItem {
77+
label: "file_id: FileId",
78+
source_range: 61..65,
79+
delete: 61..65,
80+
insert: "file_id: FileId",
81+
lookup: "file_id",
82+
},
83+
]
84+
"#]],
8585
);
8686
}
8787

8888
#[test]
8989
fn test_param_completion_nth_param() {
90-
assert_debug_snapshot!(
91-
do_magic_completion(
92-
r"
93-
fn foo(file_id: FileId) {}
94-
fn bar(file_id: FileId) {}
95-
fn baz(file<|>, x: i32) {}
96-
",
97-
),
98-
@r###"
99-
[
100-
CompletionItem {
101-
label: "file_id: FileId",
102-
source_range: 61..65,
103-
delete: 61..65,
104-
insert: "file_id: FileId",
105-
lookup: "file_id",
106-
},
107-
]
108-
"###
90+
check(
91+
r#"
92+
fn foo(file_id: FileId) {}
93+
fn bar(file_id: FileId) {}
94+
fn baz(file<|>, x: i32) {}
95+
"#,
96+
expect![[r#"
97+
[
98+
CompletionItem {
99+
label: "file_id: FileId",
100+
source_range: 61..65,
101+
delete: 61..65,
102+
insert: "file_id: FileId",
103+
lookup: "file_id",
104+
},
105+
]
106+
"#]],
109107
);
110108
}
111109

112110
#[test]
113111
fn test_param_completion_trait_param() {
114-
assert_debug_snapshot!(
115-
do_magic_completion(
116-
r"
117-
pub(crate) trait SourceRoot {
118-
pub fn contains(&self, file_id: FileId) -> bool;
119-
pub fn module_map(&self) -> &ModuleMap;
120-
pub fn lines(&self, file_id: FileId) -> &LineIndex;
121-
pub fn syntax(&self, file<|>)
122-
}
123-
",
124-
),
125-
@r###"
126-
[
127-
CompletionItem {
128-
label: "file_id: FileId",
129-
source_range: 208..212,
130-
delete: 208..212,
131-
insert: "file_id: FileId",
132-
lookup: "file_id",
133-
},
134-
]
135-
"###
112+
check(
113+
r#"
114+
pub(crate) trait SourceRoot {
115+
pub fn contains(&self, file_id: FileId) -> bool;
116+
pub fn module_map(&self) -> &ModuleMap;
117+
pub fn lines(&self, file_id: FileId) -> &LineIndex;
118+
pub fn syntax(&self, file<|>)
119+
}
120+
"#,
121+
expect![[r#"
122+
[
123+
CompletionItem {
124+
label: "file_id: FileId",
125+
source_range: 208..212,
126+
delete: 208..212,
127+
insert: "file_id: FileId",
128+
lookup: "file_id",
129+
},
130+
]
131+
"#]],
136132
);
137133
}
138134
}

crates/ra_ide/src/completion/complete_macro_in_item_position.rs

Lines changed: 16 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -15,130 +15,27 @@ pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &Compl
1515

1616
#[cfg(test)]
1717
mod tests {
18-
use insta::assert_debug_snapshot;
18+
use expect::{expect, Expect};
1919

20-
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind};
20+
use crate::completion::{test_utils::completion_list, CompletionKind};
2121

22-
fn do_reference_completion(code: &str) -> Vec<CompletionItem> {
23-
do_completion(code, CompletionKind::Reference)
22+
fn check(ra_fixture: &str, expect: Expect) {
23+
let actual = completion_list(ra_fixture, CompletionKind::Reference);
24+
expect.assert_eq(&actual)
2425
}
2526

2627
#[test]
2728
fn completes_macros_as_item() {
28-
assert_debug_snapshot!(
29-
do_reference_completion(
30-
"
31-
//- /main.rs
32-
macro_rules! foo {
33-
() => {}
34-
}
35-
36-
fn foo() {}
37-
38-
<|>
39-
"
40-
),
41-
@r###"
42-
[
43-
CompletionItem {
44-
label: "foo!(…)",
45-
source_range: 48..48,
46-
delete: 48..48,
47-
insert: "foo!($0)",
48-
kind: Macro,
49-
detail: "macro_rules! foo",
50-
},
51-
]
52-
"###
53-
);
54-
}
55-
56-
#[test]
57-
fn completes_vec_macros_with_square_brackets() {
58-
assert_debug_snapshot!(
59-
do_reference_completion(
60-
"
61-
//- /main.rs
62-
/// Creates a [`Vec`] containing the arguments.
63-
///
64-
/// - Create a [`Vec`] containing a given list of elements:
65-
///
66-
/// ```
67-
/// let v = vec![1, 2, 3];
68-
/// assert_eq!(v[0], 1);
69-
/// assert_eq!(v[1], 2);
70-
/// assert_eq!(v[2], 3);
71-
/// ```
72-
macro_rules! vec {
73-
() => {}
74-
}
75-
76-
fn foo() {}
77-
78-
<|>
79-
"
80-
),
81-
@r###"
82-
[
83-
CompletionItem {
84-
label: "vec![…]",
85-
source_range: 282..282,
86-
delete: 282..282,
87-
insert: "vec![$0]",
88-
kind: Macro,
89-
detail: "macro_rules! vec",
90-
documentation: Documentation(
91-
"Creates a [`Vec`] containing the arguments.\n\n- Create a [`Vec`] containing a given list of elements:\n\n```\nlet v = vec![1, 2, 3];\nassert_eq!(v[0], 1);\nassert_eq!(v[1], 2);\nassert_eq!(v[2], 3);\n```",
92-
),
93-
},
94-
]
95-
"###
96-
);
97-
}
98-
99-
#[test]
100-
fn completes_macros_braces_guessing() {
101-
assert_debug_snapshot!(
102-
do_reference_completion(
103-
"
104-
//- /main.rs
105-
/// Foo
106-
///
107-
/// Not call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.
108-
/// Call as `let _=foo! { hello world };`
109-
macro_rules! foo {
110-
() => {}
111-
}
112-
113-
fn main() {
114-
<|>
115-
}
116-
"
117-
),
118-
@r###"
119-
[
120-
CompletionItem {
121-
label: "foo! {…}",
122-
source_range: 164..164,
123-
delete: 164..164,
124-
insert: "foo! {$0}",
125-
kind: Macro,
126-
detail: "macro_rules! foo",
127-
documentation: Documentation(
128-
"Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`",
129-
),
130-
},
131-
CompletionItem {
132-
label: "main()",
133-
source_range: 164..164,
134-
delete: 164..164,
135-
insert: "main()$0",
136-
kind: Function,
137-
lookup: "main",
138-
detail: "fn main()",
139-
},
140-
]
141-
"###
142-
);
29+
check(
30+
r#"
31+
macro_rules! foo { () => {} }
32+
fn foo() {}
33+
34+
<|>
35+
"#,
36+
expect![[r#"
37+
ma foo!(…) macro_rules! foo
38+
"#]],
39+
)
14340
}
14441
}

crates/ra_ide/src/completion/complete_pattern.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ mod tests {
130130
delete: 90..90,
131131
insert: "m!($0)",
132132
kind: Macro,
133+
lookup: "m!",
133134
detail: "macro_rules! m",
134135
},
135136
]

crates/ra_ide/src/completion/complete_qualified_path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@ mod tests {
11891189
delete: 82..82,
11901190
insert: "foo!($0)",
11911191
kind: Macro,
1192+
lookup: "foo!",
11921193
detail: "#[macro_export]\nmacro_rules! foo",
11931194
},
11941195
CompletionItem {

crates/ra_ide/src/completion/complete_unqualified_path.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ mod tests {
785785
delete: 256..256,
786786
insert: "bar!($0)",
787787
kind: Macro,
788+
lookup: "bar!",
788789
detail: "macro_rules! bar",
789790
},
790791
CompletionItem {
@@ -793,6 +794,7 @@ mod tests {
793794
delete: 256..256,
794795
insert: "baz!($0)",
795796
kind: Macro,
797+
lookup: "baz!",
796798
detail: "#[macro_export]\nmacro_rules! baz",
797799
},
798800
CompletionItem {
@@ -801,6 +803,7 @@ mod tests {
801803
delete: 256..256,
802804
insert: "foo!($0)",
803805
kind: Macro,
806+
lookup: "foo!",
804807
detail: "macro_rules! foo",
805808
},
806809
CompletionItem {
@@ -854,6 +857,7 @@ mod tests {
854857
delete: 50..50,
855858
insert: "foo!($0)",
856859
kind: Macro,
860+
lookup: "foo!",
857861
detail: "macro_rules! foo",
858862
},
859863
CompletionItem {
@@ -893,6 +897,7 @@ mod tests {
893897
delete: 58..58,
894898
insert: "foo!($0)",
895899
kind: Macro,
900+
lookup: "foo!",
896901
detail: "macro_rules! foo",
897902
},
898903
CompletionItem {
@@ -932,6 +937,7 @@ mod tests {
932937
delete: 51..51,
933938
insert: "foo!($0)",
934939
kind: Macro,
940+
lookup: "foo!",
935941
detail: "macro_rules! foo",
936942
},
937943
CompletionItem {
@@ -1005,6 +1011,7 @@ mod tests {
10051011
delete: 80..80,
10061012
insert: "m!($0)",
10071013
kind: Macro,
1014+
lookup: "m!",
10081015
detail: "macro_rules! m",
10091016
},
10101017
CompletionItem {
@@ -1058,6 +1065,7 @@ mod tests {
10581065
delete: 80..81,
10591066
insert: "m!($0)",
10601067
kind: Macro,
1068+
lookup: "m!",
10611069
detail: "macro_rules! m",
10621070
},
10631071
CompletionItem {
@@ -1111,6 +1119,7 @@ mod tests {
11111119
delete: 80..81,
11121120
insert: "m!($0)",
11131121
kind: Macro,
1122+
lookup: "m!",
11141123
detail: "macro_rules! m",
11151124
},
11161125
CompletionItem {

0 commit comments

Comments
 (0)