aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/tests/item_list.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-16 20:53:43 +0100
committerGitHub <[email protected]>2021-06-16 20:53:43 +0100
commitd6b8af44829521a9f925c4d87599efa3fef38edc (patch)
tree47119538effd381ecd8e15d422103512f2b47406 /crates/ide_completion/src/tests/item_list.rs
parentf38770cd2606148bfe764351849ea7ebea45132c (diff)
parentaa644b55859c6b5c6695a5d4fb35d1b6efbbebcc (diff)
Merge #9301
9301: internal: Start refactoring ide_completion tests r=Veykril a=Veykril Our current completion test infra resovles around usually just checking a specific `CompletionKind` which is suboptimal. We only see what we want to see in tests with this causing us to miss a lot of incorrect completions we are doing. Instead we should test for different cursor locations for all kinds(sans the magic kind maybe? not sure yet). This way we will also see potential duplicate completions that merely different in their kind. Also since most completion submodules complete things in tests of other modules due to the tests overlapping it makes more sense to group these tests differently which implies moving them to a new module. Exceptions for this might be stuff like attribute completion as these cannot currently interfere. I only wrote a few tests to check for completions in `ItemList` position so far and I already found a few incorrect/irrelevant completions as these haven't been tested properly due to them being hidden by the `CompletionKind` filtering. I think `CompletionKind` doesn't really seem to be beneficial to me as to I can't think of a occasion where we would want to only check a specific completion kind. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/tests/item_list.rs')
-rw-r--r--crates/ide_completion/src/tests/item_list.rs223
1 files changed, 223 insertions, 0 deletions
diff --git a/crates/ide_completion/src/tests/item_list.rs b/crates/ide_completion/src/tests/item_list.rs
new file mode 100644
index 000000000..7c124ac37
--- /dev/null
+++ b/crates/ide_completion/src/tests/item_list.rs
@@ -0,0 +1,223 @@
1use expect_test::{expect, Expect};
2
3use crate::tests::completion_list;
4
5fn check(ra_fixture: &str, expect: Expect) {
6 let base = r#"#[rustc_builtin_macro]
7pub macro Clone {}
8enum Enum { Variant }
9struct Struct {}
10#[macro_export]
11macro_rules! foo {}
12mod bar {}
13const CONST: () = ();
14trait Trait {}
15"#;
16 let actual = completion_list(&format!("{}{}", base, ra_fixture));
17 expect.assert_eq(&actual)
18}
19
20#[test]
21fn in_mod_item_list() {
22 check(
23 r#"mod tests { $0 }"#,
24 expect![[r##"
25 kw pub(crate)
26 kw pub
27 kw unsafe
28 kw fn
29 kw const
30 kw type
31 kw impl
32 kw extern
33 kw use
34 kw trait
35 kw static
36 kw mod
37 kw enum
38 kw struct
39 kw union
40 sn tmod (Test module)
41 sn tfn (Test function)
42 sn macro_rules
43 ma foo!(…) #[macro_export] macro_rules! foo
44 "##]],
45 )
46}
47
48#[test]
49fn in_source_file_item_list() {
50 check(
51 r#"$0"#,
52 expect![[r##"
53 kw pub(crate)
54 kw pub
55 kw unsafe
56 kw fn
57 kw const
58 kw type
59 kw impl
60 kw extern
61 kw use
62 kw trait
63 kw static
64 kw mod
65 kw enum
66 kw struct
67 kw union
68 sn tmod (Test module)
69 sn tfn (Test function)
70 sn macro_rules
71 md bar
72 ma foo!(…) #[macro_export] macro_rules! foo
73 ma foo!(…) #[macro_export] macro_rules! foo
74 "##]],
75 )
76}
77
78#[test]
79fn in_item_list_after_attr() {
80 check(
81 r#"#[attr] $0"#,
82 expect![[r#"
83 kw pub(crate)
84 kw pub
85 kw unsafe
86 kw fn
87 kw const
88 kw type
89 kw impl
90 kw extern
91 kw use
92 kw trait
93 kw static
94 kw mod
95 kw enum
96 kw struct
97 kw union
98 sn tmod (Test module)
99 sn tfn (Test function)
100 sn macro_rules
101 "#]],
102 )
103}
104
105#[test]
106fn in_qualified_path() {
107 check(
108 r#"crate::$0"#,
109 expect![[r##"
110 kw pub(crate)
111 kw pub
112 kw unsafe
113 kw fn
114 kw const
115 kw type
116 kw impl
117 kw extern
118 kw use
119 kw trait
120 kw static
121 kw mod
122 kw enum
123 kw struct
124 kw union
125 md bar
126 ma foo!(…) #[macro_export] macro_rules! foo
127 "##]],
128 )
129}
130
131#[test]
132fn after_unsafe_token() {
133 check(
134 r#"unsafe $0"#,
135 expect![[r#"
136 kw fn
137 kw trait
138 kw impl
139 "#]],
140 );
141}
142
143#[test]
144fn after_visibility() {
145 check(
146 r#"pub $0"#,
147 expect![[r#"
148 kw unsafe
149 kw fn
150 kw const
151 kw type
152 kw use
153 kw trait
154 kw static
155 kw mod
156 kw enum
157 kw struct
158 kw union
159 "#]],
160 );
161}
162
163#[test]
164fn after_visibility_unsafe() {
165 // FIXME this shouldn't show `impl`
166 check(
167 r#"pub unsafe $0"#,
168 expect![[r#"
169 kw fn
170 kw trait
171 kw impl
172 "#]],
173 );
174}
175
176#[test]
177fn in_impl_assoc_item_list() {
178 check(
179 r#"impl Struct { $0 }"#,
180 expect![[r##"
181 kw pub(crate)
182 kw pub
183 kw unsafe
184 kw fn
185 kw const
186 kw type
187 md bar
188 ma foo!(…) #[macro_export] macro_rules! foo
189 ma foo!(…) #[macro_export] macro_rules! foo
190 "##]],
191 )
192}
193
194#[test]
195fn in_impl_assoc_item_list_after_attr() {
196 check(
197 r#"impl Struct { #[attr] $0 }"#,
198 expect![[r#"
199 kw pub(crate)
200 kw pub
201 kw unsafe
202 kw fn
203 kw const
204 kw type
205 "#]],
206 )
207}
208
209#[test]
210fn in_trait_assoc_item_list() {
211 check(
212 r"trait Foo { $0 }",
213 expect![[r##"
214 kw unsafe
215 kw fn
216 kw const
217 kw type
218 md bar
219 ma foo!(…) #[macro_export] macro_rules! foo
220 ma foo!(…) #[macro_export] macro_rules! foo
221 "##]],
222 );
223}