diff options
Diffstat (limited to 'crates/hir_def/src/body/tests/block.rs')
-rw-r--r-- | crates/hir_def/src/body/tests/block.rs | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/crates/hir_def/src/body/tests/block.rs b/crates/hir_def/src/body/tests/block.rs new file mode 100644 index 000000000..062560a70 --- /dev/null +++ b/crates/hir_def/src/body/tests/block.rs | |||
@@ -0,0 +1,230 @@ | |||
1 | use super::*; | ||
2 | use expect_test::expect; | ||
3 | |||
4 | #[test] | ||
5 | fn inner_item_smoke() { | ||
6 | check_at( | ||
7 | r#" | ||
8 | struct inner {} | ||
9 | fn outer() { | ||
10 | $0 | ||
11 | fn inner() {} | ||
12 | } | ||
13 | "#, | ||
14 | expect![[r#" | ||
15 | block scope | ||
16 | inner: v | ||
17 | |||
18 | crate | ||
19 | inner: t | ||
20 | outer: v | ||
21 | "#]], | ||
22 | ); | ||
23 | } | ||
24 | |||
25 | #[test] | ||
26 | fn use_from_crate() { | ||
27 | check_at( | ||
28 | r#" | ||
29 | struct Struct; | ||
30 | fn outer() { | ||
31 | use Struct; | ||
32 | use crate::Struct as CrateStruct; | ||
33 | use self::Struct as SelfStruct; | ||
34 | $0 | ||
35 | } | ||
36 | "#, | ||
37 | expect![[r#" | ||
38 | block scope | ||
39 | CrateStruct: t v | ||
40 | SelfStruct: t v | ||
41 | Struct: t v | ||
42 | |||
43 | crate | ||
44 | Struct: t v | ||
45 | outer: v | ||
46 | "#]], | ||
47 | ); | ||
48 | } | ||
49 | |||
50 | #[test] | ||
51 | fn merge_namespaces() { | ||
52 | check_at( | ||
53 | r#" | ||
54 | struct name {} | ||
55 | fn outer() { | ||
56 | fn name() {} | ||
57 | |||
58 | use name as imported; // should import both `name`s | ||
59 | |||
60 | $0 | ||
61 | } | ||
62 | "#, | ||
63 | expect![[r#" | ||
64 | block scope | ||
65 | imported: t v | ||
66 | name: v | ||
67 | |||
68 | crate | ||
69 | name: t | ||
70 | outer: v | ||
71 | "#]], | ||
72 | ); | ||
73 | } | ||
74 | |||
75 | #[test] | ||
76 | fn nested_blocks() { | ||
77 | check_at( | ||
78 | r#" | ||
79 | fn outer() { | ||
80 | struct inner1 {} | ||
81 | fn inner() { | ||
82 | use inner1; | ||
83 | use outer; | ||
84 | fn inner2() {} | ||
85 | $0 | ||
86 | } | ||
87 | } | ||
88 | "#, | ||
89 | expect![[r#" | ||
90 | block scope | ||
91 | inner1: t | ||
92 | inner2: v | ||
93 | outer: v | ||
94 | |||
95 | block scope | ||
96 | inner: v | ||
97 | inner1: t | ||
98 | |||
99 | crate | ||
100 | outer: v | ||
101 | "#]], | ||
102 | ); | ||
103 | } | ||
104 | |||
105 | #[test] | ||
106 | fn super_imports() { | ||
107 | check_at( | ||
108 | r#" | ||
109 | mod module { | ||
110 | fn f() { | ||
111 | use super::Struct; | ||
112 | $0 | ||
113 | } | ||
114 | } | ||
115 | |||
116 | struct Struct {} | ||
117 | "#, | ||
118 | expect![[r#" | ||
119 | block scope | ||
120 | Struct: t | ||
121 | |||
122 | crate | ||
123 | Struct: t | ||
124 | module: t | ||
125 | |||
126 | crate::module | ||
127 | f: v | ||
128 | "#]], | ||
129 | ); | ||
130 | } | ||
131 | |||
132 | #[test] | ||
133 | fn legacy_macro_items() { | ||
134 | // Checks that legacy-scoped `macro_rules!` from parent namespaces are resolved and expanded | ||
135 | // correctly. | ||
136 | check_at( | ||
137 | r#" | ||
138 | macro_rules! hit { | ||
139 | () => { | ||
140 | struct Hit {} | ||
141 | } | ||
142 | } | ||
143 | |||
144 | fn f() { | ||
145 | hit!(); | ||
146 | $0 | ||
147 | } | ||
148 | "#, | ||
149 | expect![[r#" | ||
150 | block scope | ||
151 | Hit: t | ||
152 | |||
153 | crate | ||
154 | f: v | ||
155 | "#]], | ||
156 | ); | ||
157 | } | ||
158 | |||
159 | #[test] | ||
160 | fn macro_resolve() { | ||
161 | check_at( | ||
162 | r#" | ||
163 | //- /lib.rs crate:lib deps:core | ||
164 | use core::mark; | ||
165 | |||
166 | fn f() { | ||
167 | fn nested() { | ||
168 | mark::hit!(Hit); | ||
169 | $0 | ||
170 | } | ||
171 | } | ||
172 | //- /core.rs crate:core | ||
173 | pub mod mark { | ||
174 | #[macro_export] | ||
175 | macro_rules! _hit { | ||
176 | ($name:ident) => { | ||
177 | struct $name {} | ||
178 | } | ||
179 | } | ||
180 | |||
181 | pub use crate::_hit as hit; | ||
182 | } | ||
183 | "#, | ||
184 | expect![[r#" | ||
185 | block scope | ||
186 | Hit: t | ||
187 | |||
188 | block scope | ||
189 | nested: v | ||
190 | |||
191 | crate | ||
192 | f: v | ||
193 | mark: t | ||
194 | "#]], | ||
195 | ); | ||
196 | } | ||
197 | |||
198 | #[test] | ||
199 | fn macro_resolve_legacy() { | ||
200 | check_at( | ||
201 | r#" | ||
202 | //- /lib.rs | ||
203 | mod module; | ||
204 | |||
205 | //- /module.rs | ||
206 | macro_rules! m { | ||
207 | () => { | ||
208 | struct Def {} | ||
209 | }; | ||
210 | } | ||
211 | |||
212 | fn f() { | ||
213 | { | ||
214 | m!(); | ||
215 | $0 | ||
216 | } | ||
217 | } | ||
218 | "#, | ||
219 | expect![[r#" | ||
220 | block scope | ||
221 | Def: t | ||
222 | |||
223 | crate | ||
224 | module: t | ||
225 | |||
226 | crate::module | ||
227 | f: v | ||
228 | "#]], | ||
229 | ) | ||
230 | } | ||