diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-17 13:01:43 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-17 13:01:43 +0100 |
commit | c82a9141abe6b6cbf5b55710dc8a315a3839081b (patch) | |
tree | 1d130833fa51a6fd46e3ff61f3f68155e546c535 /crates/ide_completion/src/tests | |
parent | 3b58d8f785917b4212cd917fced6c3006210e4d3 (diff) | |
parent | 9353f36516e5b4026ce3a181d578c3a63876a18f (diff) |
Merge #9310
9310: internal: Refine and test UseTree completions r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/tests')
-rw-r--r-- | crates/ide_completion/src/tests/use_tree.rs | 255 |
1 files changed, 255 insertions, 0 deletions
diff --git a/crates/ide_completion/src/tests/use_tree.rs b/crates/ide_completion/src/tests/use_tree.rs new file mode 100644 index 000000000..7e6748ccc --- /dev/null +++ b/crates/ide_completion/src/tests/use_tree.rs | |||
@@ -0,0 +1,255 @@ | |||
1 | use expect_test::{expect, Expect}; | ||
2 | |||
3 | use crate::tests::completion_list; | ||
4 | |||
5 | fn check(ra_fixture: &str, expect: Expect) { | ||
6 | let actual = completion_list(ra_fixture); | ||
7 | expect.assert_eq(&actual) | ||
8 | } | ||
9 | |||
10 | #[test] | ||
11 | fn use_tree_start() { | ||
12 | cov_mark::check!(only_completes_modules_in_import); | ||
13 | check( | ||
14 | r#" | ||
15 | //- /lib.rs crate:main deps:other_crate | ||
16 | use f$0 | ||
17 | |||
18 | struct Foo; | ||
19 | mod foo {} | ||
20 | //- /other_crate/lib.rs crate:other_crate | ||
21 | // nothing here | ||
22 | "#, | ||
23 | expect![[r#" | ||
24 | kw crate:: | ||
25 | kw self:: | ||
26 | kw super:: | ||
27 | md foo | ||
28 | md other_crate | ||
29 | "#]], | ||
30 | ); | ||
31 | } | ||
32 | |||
33 | #[test] | ||
34 | fn dont_complete_current_use() { | ||
35 | cov_mark::check!(dont_complete_current_use); | ||
36 | check(r#"use self::foo$0;"#, expect![[r#""#]]); | ||
37 | check( | ||
38 | r#" | ||
39 | mod foo { pub struct S; } | ||
40 | use self::{foo::*, bar$0}; | ||
41 | "#, | ||
42 | expect![[r#" | ||
43 | kw self | ||
44 | st S | ||
45 | md foo | ||
46 | "#]], | ||
47 | ); | ||
48 | } | ||
49 | |||
50 | #[test] | ||
51 | fn nested_use_tree() { | ||
52 | check( | ||
53 | r#" | ||
54 | mod foo { | ||
55 | pub mod bar { | ||
56 | pub struct FooBar; | ||
57 | } | ||
58 | } | ||
59 | use foo::{bar::$0} | ||
60 | "#, | ||
61 | expect![[r#" | ||
62 | st FooBar | ||
63 | "#]], | ||
64 | ); | ||
65 | check( | ||
66 | r#" | ||
67 | mod foo { | ||
68 | pub mod bar { | ||
69 | pub struct FooBar; | ||
70 | } | ||
71 | } | ||
72 | use foo::{$0} | ||
73 | "#, | ||
74 | expect![[r#" | ||
75 | kw self | ||
76 | md bar | ||
77 | "#]], | ||
78 | ); | ||
79 | } | ||
80 | |||
81 | #[test] | ||
82 | fn deeply_nested_use_tree() { | ||
83 | check( | ||
84 | r#" | ||
85 | mod foo { | ||
86 | pub mod bar { | ||
87 | pub mod baz { | ||
88 | pub struct FooBarBaz; | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | use foo::{bar::{baz::$0}} | ||
93 | "#, | ||
94 | expect![[r#" | ||
95 | st FooBarBaz | ||
96 | "#]], | ||
97 | ); | ||
98 | check( | ||
99 | r#" | ||
100 | mod foo { | ||
101 | pub mod bar { | ||
102 | pub mod baz { | ||
103 | pub struct FooBarBaz; | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | use foo::{bar::{$0}} | ||
108 | "#, | ||
109 | expect![[r#" | ||
110 | kw self | ||
111 | md baz | ||
112 | "#]], | ||
113 | ); | ||
114 | } | ||
115 | |||
116 | #[test] | ||
117 | fn plain_qualified_use_tree() { | ||
118 | check( | ||
119 | r#" | ||
120 | use foo::$0 | ||
121 | |||
122 | mod foo { | ||
123 | struct Private; | ||
124 | pub struct Foo; | ||
125 | } | ||
126 | struct Bar; | ||
127 | "#, | ||
128 | expect![[r#" | ||
129 | st Foo | ||
130 | "#]], | ||
131 | ); | ||
132 | } | ||
133 | |||
134 | #[test] | ||
135 | fn self_qualified_use_tree() { | ||
136 | check( | ||
137 | r#" | ||
138 | use self::$0 | ||
139 | |||
140 | mod foo {} | ||
141 | struct Bar; | ||
142 | "#, | ||
143 | expect![[r#" | ||
144 | md foo | ||
145 | st Bar | ||
146 | "#]], | ||
147 | ); | ||
148 | } | ||
149 | |||
150 | #[test] | ||
151 | fn super_qualified_use_tree() { | ||
152 | check( | ||
153 | r#" | ||
154 | mod bar { | ||
155 | use super::$0 | ||
156 | } | ||
157 | |||
158 | mod foo {} | ||
159 | struct Bar; | ||
160 | "#, | ||
161 | expect![[r#" | ||
162 | kw super:: | ||
163 | st Bar | ||
164 | md bar | ||
165 | md foo | ||
166 | "#]], | ||
167 | ); | ||
168 | } | ||
169 | |||
170 | #[test] | ||
171 | fn super_super_qualified_use_tree() { | ||
172 | check( | ||
173 | r#" | ||
174 | mod a { | ||
175 | const A: usize = 0; | ||
176 | mod b { | ||
177 | const B: usize = 0; | ||
178 | mod c { use super::super::$0 } | ||
179 | } | ||
180 | } | ||
181 | "#, | ||
182 | expect![[r#" | ||
183 | kw super:: | ||
184 | md b | ||
185 | ct A | ||
186 | "#]], | ||
187 | ); | ||
188 | } | ||
189 | |||
190 | #[test] | ||
191 | fn crate_qualified_use_tree() { | ||
192 | check( | ||
193 | r#" | ||
194 | use crate::$0 | ||
195 | |||
196 | mod foo {} | ||
197 | struct Bar; | ||
198 | "#, | ||
199 | expect![[r#" | ||
200 | md foo | ||
201 | st Bar | ||
202 | "#]], | ||
203 | ); | ||
204 | } | ||
205 | |||
206 | #[test] | ||
207 | fn extern_crate_qualified_use_tree() { | ||
208 | check( | ||
209 | r#" | ||
210 | //- /lib.rs crate:main deps:other_crate | ||
211 | use other_crate::$0 | ||
212 | //- /other_crate/lib.rs crate:other_crate | ||
213 | pub struct Foo; | ||
214 | pub mod foo {} | ||
215 | "#, | ||
216 | expect![[r#" | ||
217 | st Foo | ||
218 | md foo | ||
219 | "#]], | ||
220 | ); | ||
221 | } | ||
222 | |||
223 | #[test] | ||
224 | fn pub_use_tree() { | ||
225 | check( | ||
226 | r#" | ||
227 | pub struct X; | ||
228 | pub mod bar {} | ||
229 | pub use $0; | ||
230 | "#, | ||
231 | expect![[r#" | ||
232 | kw crate:: | ||
233 | kw self:: | ||
234 | kw super:: | ||
235 | md bar | ||
236 | "#]], | ||
237 | ); | ||
238 | } | ||
239 | |||
240 | #[test] | ||
241 | fn use_tree_braces_at_start() { | ||
242 | check( | ||
243 | r#" | ||
244 | struct X; | ||
245 | mod bar {} | ||
246 | use {$0}; | ||
247 | "#, | ||
248 | expect![[r#" | ||
249 | kw crate:: | ||
250 | kw self:: | ||
251 | kw super:: | ||
252 | md bar | ||
253 | "#]], | ||
254 | ); | ||
255 | } | ||