aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/tests
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-17 12:13:12 +0100
committerLukas Wirth <[email protected]>2021-06-17 12:13:12 +0100
commite14f5cfff04942f45a4af3b45152df9672b3458a (patch)
tree0ed0353823e6194bc5f940d2033ab2c0788f19fd /crates/ide_completion/src/tests
parentd6b8af44829521a9f925c4d87599efa3fef38edc (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.rs261
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 @@
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 // 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]
35fn 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#"
46mod foo { pub struct S; }
47use self::{foo::*, bar$0};
48"#,
49 expect![[r#"
50 kw self
51 st S
52 md foo
53 "#]],
54 );
55}
56
57#[test]
58fn nested_use_tree() {
59 // FIXME: self shouldn't be here
60 check(
61 r#"
62mod foo {
63 pub mod bar {
64 pub struct FooBar;
65 }
66}
67use foo::{bar::$0}
68"#,
69 expect![[r#"
70 kw self
71 st FooBar
72 "#]],
73 );
74 check(
75 r#"
76mod foo {
77 pub mod bar {
78 pub struct FooBar;
79 }
80}
81use foo::{$0}
82"#,
83 expect![[r#"
84 kw self
85 md bar
86 "#]],
87 );
88}
89
90#[test]
91fn deeply_nested_use_tree() {
92 // FIXME: self shouldn't be here
93 check(
94 r#"
95mod foo {
96 pub mod bar {
97 pub mod baz {
98 pub struct FooBarBaz;
99 }
100 }
101}
102use foo::{bar::{baz::$0}}
103"#,
104 expect![[r#"
105 kw self
106 st FooBarBaz
107 "#]],
108 );
109 check(
110 r#"
111mod foo {
112 pub mod bar {
113 pub mod baz {
114 pub struct FooBarBaz;
115 }
116 }
117}
118use foo::{bar::{$0}}
119"#,
120 expect![[r#"
121 kw self
122 md baz
123 "#]],
124 );
125}
126
127#[test]
128fn plain_qualified_use_tree() {
129 // FIXME: self shouldn't be here
130 check(
131 r#"
132use foo::$0
133
134mod foo {
135 struct Private;
136 pub struct Foo;
137}
138struct Bar;
139"#,
140 expect![[r#"
141 kw self
142 st Foo
143 "#]],
144 );
145}
146
147#[test]
148fn self_qualified_use_tree() {
149 // FIXME: self shouldn't be here
150 check(
151 r#"
152use self::$0
153
154mod foo {}
155struct Bar;
156"#,
157 expect![[r#"
158 kw self
159 md foo
160 st Bar
161 "#]],
162 );
163}
164
165#[test]
166fn super_qualified_use_tree() {
167 // FIXME: self shouldn't be here
168 check(
169 r#"
170mod bar {
171 use super::$0
172}
173
174mod foo {}
175struct 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]
188fn super_super_qualified_use_tree() {
189 // FIXME: self shouldn't be here
190 check(
191 r#"
192mod 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]
210fn crate_qualified_use_tree() {
211 // FIXME: self shouldn't be here
212 check(
213 r#"
214use crate::$0
215
216mod foo {}
217struct Bar;
218"#,
219 expect![[r#"
220 kw self
221 md foo
222 st Bar
223 "#]],
224 );
225}
226
227#[test]
228fn extern_crate_qualified_use_tree() {
229 // FIXME: self shouldn't be here
230 check(
231 r#"
232//- /lib.rs crate:main deps:other_crate
233use other_crate::$0
234//- /other_crate/lib.rs crate:other_crate
235pub struct Foo;
236pub mod foo {}
237"#,
238 expect![[r#"
239 kw self
240 st Foo
241 md foo
242 "#]],
243 );
244}
245
246#[test]
247fn pub_use_tree() {
248 check(
249 r#"
250pub struct X;
251pub mod bar {}
252pub use $0;
253"#,
254 expect![[r#"
255 kw crate::
256 kw self
257 kw super::
258 md bar
259 "#]],
260 );
261}