aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-01-10 21:00:41 +0000
committerFlorian Diebold <[email protected]>2020-01-10 21:08:02 +0000
commitdd6ec81d658f7cd06b7ed37174b170f0e8930eed (patch)
tree34754becb9ab974946d04729c76dc31ba0ba49d1
parent19eb7fa1db7da8417314ddfafe7addbbd9c3b46a (diff)
Add test for macro expansion in various expressions
-rw-r--r--crates/ra_hir_expand/src/db.rs1
-rw-r--r--crates/ra_hir_ty/src/tests/macros.rs81
2 files changed, 81 insertions, 1 deletions
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs
index 5d12c1584..af5b22d1c 100644
--- a/crates/ra_hir_expand/src/db.rs
+++ b/crates/ra_hir_expand/src/db.rs
@@ -190,7 +190,6 @@ fn to_fragment_kind(db: &dyn AstDatabase, macro_call_id: MacroCallId) -> Fragmen
190 TUPLE_EXPR => FragmentKind::Expr, 190 TUPLE_EXPR => FragmentKind::Expr,
191 PAREN_EXPR => FragmentKind::Expr, 191 PAREN_EXPR => FragmentKind::Expr,
192 192
193 // FIXME: Add tests for following cases in hir_ty
194 FOR_EXPR => FragmentKind::Expr, 193 FOR_EXPR => FragmentKind::Expr,
195 PATH_EXPR => FragmentKind::Expr, 194 PATH_EXPR => FragmentKind::Expr,
196 LAMBDA_EXPR => FragmentKind::Expr, 195 LAMBDA_EXPR => FragmentKind::Expr,
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs
index 69c695cc8..9d09d93a7 100644
--- a/crates/ra_hir_ty/src/tests/macros.rs
+++ b/crates/ra_hir_ty/src/tests/macros.rs
@@ -136,6 +136,87 @@ fn main() {
136} 136}
137 137
138#[test] 138#[test]
139fn expr_macro_expanded_in_various_places() {
140 assert_snapshot!(
141 infer(r#"
142macro_rules! spam {
143 () => (1isize);
144}
145
146fn spam() {
147 spam!();
148 (spam!());
149 spam!().spam(spam!());
150 for _ in spam!() {}
151 || spam!();
152 while spam!() {}
153 break spam!();
154 return spam!();
155 match spam!() {
156 _ if spam!() => spam!(),
157 }
158 spam!()(spam!());
159 Spam { spam: spam!() };
160 spam!()[spam!()];
161 await spam!();
162 spam!() as usize;
163 &spam!();
164 -spam!();
165 spam!()..spam!();
166 spam!() + spam!();
167}
168"#),
169 @r###"
170 ![0; 6) '1isize': isize
171 ![0; 6) '1isize': isize
172 ![0; 6) '1isize': isize
173 ![0; 6) '1isize': isize
174 ![0; 6) '1isize': isize
175 ![0; 6) '1isize': isize
176 ![0; 6) '1isize': isize
177 ![0; 6) '1isize': isize
178 ![0; 6) '1isize': isize
179 ![0; 6) '1isize': isize
180 ![0; 6) '1isize': isize
181 ![0; 6) '1isize': isize
182 ![0; 6) '1isize': isize
183 ![0; 6) '1isize': isize
184 ![0; 6) '1isize': isize
185 ![0; 6) '1isize': isize
186 ![0; 6) '1isize': isize
187 ![0; 6) '1isize': isize
188 ![0; 6) '1isize': isize
189 ![0; 6) '1isize': isize
190 ![0; 6) '1isize': isize
191 ![0; 6) '1isize': isize
192 ![0; 6) '1isize': isize
193 ![0; 6) '1isize': isize
194 ![0; 6) '1isize': isize
195 [54; 457) '{ ...!(); }': !
196 [88; 109) 'spam!(...am!())': {unknown}
197 [115; 134) 'for _ ...!() {}': ()
198 [119; 120) '_': {unknown}
199 [132; 134) '{}': ()
200 [139; 149) '|| spam!()': || -> isize
201 [155; 171) 'while ...!() {}': ()
202 [169; 171) '{}': ()
203 [176; 189) 'break spam!()': !
204 [195; 209) 'return spam!()': !
205 [215; 269) 'match ... }': isize
206 [239; 240) '_': isize
207 [274; 290) 'spam!(...am!())': {unknown}
208 [296; 318) 'Spam {...m!() }': {unknown}
209 [324; 340) 'spam!(...am!()]': {unknown}
210 [365; 381) 'spam!(... usize': usize
211 [387; 395) '&spam!()': &isize
212 [401; 409) '-spam!()': isize
213 [415; 431) 'spam!(...pam!()': {unknown}
214 [437; 454) 'spam!(...pam!()': isize
215 "###
216 );
217}
218
219#[test]
139fn infer_type_value_macro_having_same_name() { 220fn infer_type_value_macro_having_same_name() {
140 assert_snapshot!( 221 assert_snapshot!(
141 infer(r#" 222 infer(r#"