aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/tests/use_tree.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/tests/use_tree.rs')
-rw-r--r--crates/ide_completion/src/tests/use_tree.rs255
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 @@
1use expect_test::{expect, Expect};
2
3use crate::tests::completion_list;
4
5fn check(ra_fixture: &str, expect: Expect) {
6 let actual = completion_list(ra_fixture);
7 expect.assert_eq(&actual)
8}
9
10#[test]
11fn use_tree_start() {
12 cov_mark::check!(only_completes_modules_in_import);
13 check(
14 r#"
15//- /lib.rs crate:main deps:other_crate
16use f$0
17
18struct Foo;
19mod 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]
34fn 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#"
39mod foo { pub struct S; }
40use self::{foo::*, bar$0};
41"#,
42 expect![[r#"
43 kw self
44 st S
45 md foo
46 "#]],
47 );
48}
49
50#[test]
51fn nested_use_tree() {
52 check(
53 r#"
54mod foo {
55 pub mod bar {
56 pub struct FooBar;
57 }
58}
59use foo::{bar::$0}
60"#,
61 expect![[r#"
62 st FooBar
63 "#]],
64 );
65 check(
66 r#"
67mod foo {
68 pub mod bar {
69 pub struct FooBar;
70 }
71}
72use foo::{$0}
73"#,
74 expect![[r#"
75 kw self
76 md bar
77 "#]],
78 );
79}
80
81#[test]
82fn deeply_nested_use_tree() {
83 check(
84 r#"
85mod foo {
86 pub mod bar {
87 pub mod baz {
88 pub struct FooBarBaz;
89 }
90 }
91}
92use foo::{bar::{baz::$0}}
93"#,
94 expect![[r#"
95 st FooBarBaz
96 "#]],
97 );
98 check(
99 r#"
100mod foo {
101 pub mod bar {
102 pub mod baz {
103 pub struct FooBarBaz;
104 }
105 }
106}
107use foo::{bar::{$0}}
108"#,
109 expect![[r#"
110 kw self
111 md baz
112 "#]],
113 );
114}
115
116#[test]
117fn plain_qualified_use_tree() {
118 check(
119 r#"
120use foo::$0
121
122mod foo {
123 struct Private;
124 pub struct Foo;
125}
126struct Bar;
127"#,
128 expect![[r#"
129 st Foo
130 "#]],
131 );
132}
133
134#[test]
135fn self_qualified_use_tree() {
136 check(
137 r#"
138use self::$0
139
140mod foo {}
141struct Bar;
142"#,
143 expect![[r#"
144 md foo
145 st Bar
146 "#]],
147 );
148}
149
150#[test]
151fn super_qualified_use_tree() {
152 check(
153 r#"
154mod bar {
155 use super::$0
156}
157
158mod foo {}
159struct Bar;
160"#,
161 expect![[r#"
162 kw super::
163 st Bar
164 md bar
165 md foo
166 "#]],
167 );
168}
169
170#[test]
171fn super_super_qualified_use_tree() {
172 check(
173 r#"
174mod 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]
191fn crate_qualified_use_tree() {
192 check(
193 r#"
194use crate::$0
195
196mod foo {}
197struct Bar;
198"#,
199 expect![[r#"
200 md foo
201 st Bar
202 "#]],
203 );
204}
205
206#[test]
207fn extern_crate_qualified_use_tree() {
208 check(
209 r#"
210//- /lib.rs crate:main deps:other_crate
211use other_crate::$0
212//- /other_crate/lib.rs crate:other_crate
213pub struct Foo;
214pub mod foo {}
215"#,
216 expect![[r#"
217 st Foo
218 md foo
219 "#]],
220 );
221}
222
223#[test]
224fn pub_use_tree() {
225 check(
226 r#"
227pub struct X;
228pub mod bar {}
229pub use $0;
230"#,
231 expect![[r#"
232 kw crate::
233 kw self::
234 kw super::
235 md bar
236 "#]],
237 );
238}
239
240#[test]
241fn use_tree_braces_at_start() {
242 check(
243 r#"
244struct X;
245mod bar {}
246use {$0};
247"#,
248 expect![[r#"
249 kw crate::
250 kw self::
251 kw super::
252 md bar
253 "#]],
254 );
255}