diff options
author | Lukas Wirth <[email protected]> | 2021-06-17 12:13:12 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-06-17 12:13:12 +0100 |
commit | e14f5cfff04942f45a4af3b45152df9672b3458a (patch) | |
tree | 0ed0353823e6194bc5f940d2033ab2c0788f19fd /crates/ide_completion/src/tests | |
parent | d6b8af44829521a9f925c4d87599efa3fef38edc (diff) |
Move out and rewrite UseTree completion tests
Diffstat (limited to 'crates/ide_completion/src/tests')
-rw-r--r-- | crates/ide_completion/src/tests/use_tree.rs | 261 |
1 files changed, 261 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..156ca244d --- /dev/null +++ b/crates/ide_completion/src/tests/use_tree.rs | |||
@@ -0,0 +1,261 @@ | |||
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 | // FIXME: self in this case should also get the colons | ||
24 | expect![[r#" | ||
25 | kw crate:: | ||
26 | kw self | ||
27 | kw super:: | ||
28 | md foo | ||
29 | md other_crate | ||
30 | "#]], | ||
31 | ); | ||
32 | } | ||
33 | |||
34 | #[test] | ||
35 | fn dont_complete_current_use() { | ||
36 | cov_mark::check!(dont_complete_current_use); | ||
37 | // FIXME: self shouldn't be here | ||
38 | check( | ||
39 | r#"use self::foo$0;"#, | ||
40 | expect![[r#" | ||
41 | kw self | ||
42 | "#]], | ||
43 | ); | ||
44 | check( | ||
45 | r#" | ||
46 | mod foo { pub struct S; } | ||
47 | use self::{foo::*, bar$0}; | ||
48 | "#, | ||
49 | expect![[r#" | ||
50 | kw self | ||
51 | st S | ||
52 | md foo | ||
53 | "#]], | ||
54 | ); | ||
55 | } | ||
56 | |||
57 | #[test] | ||
58 | fn nested_use_tree() { | ||
59 | // FIXME: self shouldn't be here | ||
60 | check( | ||
61 | r#" | ||
62 | mod foo { | ||
63 | pub mod bar { | ||
64 | pub struct FooBar; | ||
65 | } | ||
66 | } | ||
67 | use foo::{bar::$0} | ||
68 | "#, | ||
69 | expect![[r#" | ||
70 | kw self | ||
71 | st FooBar | ||
72 | "#]], | ||
73 | ); | ||
74 | check( | ||
75 | r#" | ||
76 | mod foo { | ||
77 | pub mod bar { | ||
78 | pub struct FooBar; | ||
79 | } | ||
80 | } | ||
81 | use foo::{$0} | ||
82 | "#, | ||
83 | expect![[r#" | ||
84 | kw self | ||
85 | md bar | ||
86 | "#]], | ||
87 | ); | ||
88 | } | ||
89 | |||
90 | #[test] | ||
91 | fn deeply_nested_use_tree() { | ||
92 | // FIXME: self shouldn't be here | ||
93 | check( | ||
94 | r#" | ||
95 | mod foo { | ||
96 | pub mod bar { | ||
97 | pub mod baz { | ||
98 | pub struct FooBarBaz; | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | use foo::{bar::{baz::$0}} | ||
103 | "#, | ||
104 | expect![[r#" | ||
105 | kw self | ||
106 | st FooBarBaz | ||
107 | "#]], | ||
108 | ); | ||
109 | check( | ||
110 | r#" | ||
111 | mod foo { | ||
112 | pub mod bar { | ||
113 | pub mod baz { | ||
114 | pub struct FooBarBaz; | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | use foo::{bar::{$0}} | ||
119 | "#, | ||
120 | expect![[r#" | ||
121 | kw self | ||
122 | md baz | ||
123 | "#]], | ||
124 | ); | ||
125 | } | ||
126 | |||
127 | #[test] | ||
128 | fn plain_qualified_use_tree() { | ||
129 | // FIXME: self shouldn't be here | ||
130 | check( | ||
131 | r#" | ||
132 | use foo::$0 | ||
133 | |||
134 | mod foo { | ||
135 | struct Private; | ||
136 | pub struct Foo; | ||
137 | } | ||
138 | struct Bar; | ||
139 | "#, | ||
140 | expect![[r#" | ||
141 | kw self | ||
142 | st Foo | ||
143 | "#]], | ||
144 | ); | ||
145 | } | ||
146 | |||
147 | #[test] | ||
148 | fn self_qualified_use_tree() { | ||
149 | // FIXME: self shouldn't be here | ||
150 | check( | ||
151 | r#" | ||
152 | use self::$0 | ||
153 | |||
154 | mod foo {} | ||
155 | struct Bar; | ||
156 | "#, | ||
157 | expect![[r#" | ||
158 | kw self | ||
159 | md foo | ||
160 | st Bar | ||
161 | "#]], | ||
162 | ); | ||
163 | } | ||
164 | |||
165 | #[test] | ||
166 | fn super_qualified_use_tree() { | ||
167 | // FIXME: self shouldn't be here | ||
168 | check( | ||
169 | r#" | ||
170 | mod bar { | ||
171 | use super::$0 | ||
172 | } | ||
173 | |||
174 | mod foo {} | ||
175 | struct Bar; | ||
176 | "#, | ||
177 | expect![[r#" | ||
178 | kw self | ||
179 | kw super:: | ||
180 | st Bar | ||
181 | md bar | ||
182 | md foo | ||
183 | "#]], | ||
184 | ); | ||
185 | } | ||
186 | |||
187 | #[test] | ||
188 | fn super_super_qualified_use_tree() { | ||
189 | // FIXME: self shouldn't be here | ||
190 | check( | ||
191 | r#" | ||
192 | mod a { | ||
193 | const A: usize = 0; | ||
194 | mod b { | ||
195 | const B: usize = 0; | ||
196 | mod c { use super::super::$0 } | ||
197 | } | ||
198 | } | ||
199 | "#, | ||
200 | expect![[r#" | ||
201 | kw self | ||
202 | kw super:: | ||
203 | md b | ||
204 | ct A | ||
205 | "#]], | ||
206 | ); | ||
207 | } | ||
208 | |||
209 | #[test] | ||
210 | fn crate_qualified_use_tree() { | ||
211 | // FIXME: self shouldn't be here | ||
212 | check( | ||
213 | r#" | ||
214 | use crate::$0 | ||
215 | |||
216 | mod foo {} | ||
217 | struct Bar; | ||
218 | "#, | ||
219 | expect![[r#" | ||
220 | kw self | ||
221 | md foo | ||
222 | st Bar | ||
223 | "#]], | ||
224 | ); | ||
225 | } | ||
226 | |||
227 | #[test] | ||
228 | fn extern_crate_qualified_use_tree() { | ||
229 | // FIXME: self shouldn't be here | ||
230 | check( | ||
231 | r#" | ||
232 | //- /lib.rs crate:main deps:other_crate | ||
233 | use other_crate::$0 | ||
234 | //- /other_crate/lib.rs crate:other_crate | ||
235 | pub struct Foo; | ||
236 | pub mod foo {} | ||
237 | "#, | ||
238 | expect![[r#" | ||
239 | kw self | ||
240 | st Foo | ||
241 | md foo | ||
242 | "#]], | ||
243 | ); | ||
244 | } | ||
245 | |||
246 | #[test] | ||
247 | fn pub_use_tree() { | ||
248 | check( | ||
249 | r#" | ||
250 | pub struct X; | ||
251 | pub mod bar {} | ||
252 | pub use $0; | ||
253 | "#, | ||
254 | expect![[r#" | ||
255 | kw crate:: | ||
256 | kw self | ||
257 | kw super:: | ||
258 | md bar | ||
259 | "#]], | ||
260 | ); | ||
261 | } | ||