|
|
@@ -270,27 +270,28 @@ fn foo() { |
270 | |
270 | |
271 | #[test] |
271 | #[test] |
272 | fn test_join_lines_diverging_block() { |
272 | fn test_join_lines_diverging_block() { |
273 | let before = r" |
273 | check_join_lines( |
274 | fn foo() { |
274 | r" |
275 | loop { |
275 | fn foo() { |
276 | match x { |
276 | loop { |
277 | 92 => $0{ |
277 | match x { |
278 | continue; |
278 | 92 => $0{ |
279 | } |
279 | continue; |
280 | } |
| |
281 | } |
| |
282 | } |
| |
283 | "; |
| |
284 | let after = r" |
| |
285 | fn foo() { |
| |
286 | loop { |
| |
287 | match x { |
| |
288 | 92 => $0continue, |
| |
289 | } |
| |
290 | } |
| |
291 | } |
280 | } |
292 | "; |
281 | } |
293 | check_join_lines(before, after); |
282 | } |
| |
283 | } |
| |
284 | ", |
| |
285 | r" |
| |
286 | fn foo() { |
| |
287 | loop { |
| |
288 | match x { |
| |
289 | 92 => $0continue, |
| |
290 | } |
| |
291 | } |
| |
292 | } |
| |
293 | ", |
| |
294 | ); |
294 | } |
295 | } |
295 | |
296 | |
296 | #[test] |
297 | #[test] |
|
|
|
@@ -100,147 +100,137 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<St |
100 | |
100 | |
101 | #[cfg(test)] |
101 | #[cfg(test)] |
102 | mod tests { |
102 | mod tests { |
103 | use test_utils::assert_eq_text; |
103 | use expect_test::expect; |
104 | |
104 | |
105 | use crate::fixture; |
105 | use crate::fixture; |
106 | |
106 | |
| |
107 | fn check(ra_fixture: &str, expect: expect_test::Expect) { |
| |
108 | let (analysis, file_id) = fixture::file(ra_fixture); |
| |
109 | let syn = analysis.syntax_tree(file_id, None).unwrap(); |
| |
110 | expect.assert_eq(&syn) |
| |
111 | } |
| |
112 | fn check_range(ra_fixture: &str, expect: expect_test::Expect) { |
| |
113 | let (analysis, frange) = fixture::range(ra_fixture); |
| |
114 | let syn = analysis.syntax_tree(frange.file_id, Some(frange.range)).unwrap(); |
| |
115 | expect.assert_eq(&syn) |
| |
116 | } |
| |
117 | |
107 | #[test] |
118 | #[test] |
108 | fn test_syntax_tree_without_range() { |
119 | fn test_syntax_tree_without_range() { |
109 | // Basic syntax |
120 | // Basic syntax |
110 | let (analysis, file_id) = fixture::file(r#"fn foo() {}"#); |
121 | check( |
111 | let syn = analysis.syntax_tree(file_id, None).unwrap(); |
122 | r#"fn foo() {}"#, |
112 | |
123 | expect![[r#" |
113 | assert_eq_text!( |
124 | [email protected] |
114 | r#" |
125 | [email protected] |
115 | [email protected] |
126 | [email protected] "fn" |
116 | [email protected] |
127 | [email protected] " " |
117 | [email protected] "fn" |
128 | [email protected] |
118 | [email protected] " " |
129 | [email protected] "foo" |
119 | [email protected] |
130 | [email protected] |
120 | [email protected] "foo" |
131 | [email protected] "(" |
121 | [email protected] |
132 | [email protected] ")" |
122 | [email protected] "(" |
133 | [email protected] " " |
123 | [email protected] ")" |
134 | [email protected] |
124 | [email protected] " " |
135 | [email protected] "{" |
125 | [email protected] |
136 | [email protected] "}" |
126 | [email protected] "{" |
137 | "#]], |
127 | [email protected] "}" |
| |
128 | "# |
| |
129 | .trim(), |
| |
130 | syn.trim() |
| |
131 | ); |
138 | ); |
132 | |
139 | |
133 | let (analysis, file_id) = fixture::file( |
140 | check( |
134 | r#" |
141 | r#" |
135 | fn test() { |
142 | fn test() { |
136 | assert!(" |
143 | assert!(" |
137 | fn foo() { |
144 | fn foo() { |
138 | } |
145 | } |
139 | ", ""); |
146 | ", ""); |
140 | }"# |
147 | }"#, |
141 | .trim(), |
148 | expect![[r#" |
142 | ); |
149 | [email protected] |
143 | let syn = analysis.syntax_tree(file_id, None).unwrap(); |
150 | [email protected] |
144 | |
151 | [email protected] "fn" |
145 | assert_eq_text!( |
152 | [email protected] " " |
146 | r#" |
153 | [email protected] |
147 | [email protected] |
154 | [email protected] "test" |
148 | [email protected] |
155 | [email protected] |
149 | [email protected] "fn" |
156 | [email protected] "(" |
150 | [email protected] " " |
157 | [email protected] ")" |
151 | [email protected] |
158 | [email protected] " " |
152 | [email protected] "test" |
159 | [email protected] |
153 | [email protected] |
160 | [email protected] "{" |
154 | [email protected] "(" |
161 | [email protected] "\n " |
155 | [email protected] ")" |
162 | [email protected] |
156 | [email protected] " " |
163 | [email protected] |
157 | [email protected] |
164 | [email protected] |
158 | [email protected] "{" |
165 | [email protected] |
159 | [email protected] "\n " |
166 | [email protected] |
160 | [email protected] |
167 | [email protected] "assert" |
161 | [email protected] |
168 | [email protected] "!" |
162 | [email protected] |
169 | [email protected] |
163 | [email protected] |
170 | [email protected] "(" |
164 | [email protected] |
171 | [email protected] "\"\n fn foo() {\n ..." |
165 | [email protected] "assert" |
172 | [email protected] "," |
166 | [email protected] "!" |
173 | [email protected] " " |
167 | [email protected] |
174 | [email protected] "\"\"" |
168 | [email protected] "(" |
175 | [email protected] ")" |
169 | [email protected] "\"\n fn foo() {\n ..." |
176 | [email protected] ";" |
170 | [email protected] "," |
177 | [email protected] "\n" |
171 | [email protected] " " |
178 | [email protected] "}" |
172 | [email protected] "\"\"" |
179 | "#]], |
173 | [email protected] ")" |
180 | ) |
174 | [email protected] ";" |
| |
175 | [email protected] "\n" |
| |
176 | [email protected] "}" |
| |
177 | "# |
| |
178 | .trim(), |
| |
179 | syn.trim() |
| |
180 | ); |
| |
181 | } |
181 | } |
182 | |
182 | |
183 | #[test] |
183 | #[test] |
184 | fn test_syntax_tree_with_range() { |
184 | fn test_syntax_tree_with_range() { |
185 | let (analysis, range) = fixture::range(r#"$0fn foo() {}$0"#.trim()); |
185 | check_range( |
186 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); |
186 | r#"$0fn foo() {}$0"#, |
187 | |
187 | expect![[r#" |
188 | assert_eq_text!( |
188 | [email protected] |
189 | r#" |
189 | [email protected] "fn" |
190 | [email protected] |
190 | [email protected] " " |
191 | [email protected] "fn" |
191 | [email protected] |
192 | [email protected] " " |
192 | [email protected] "foo" |
193 | [email protected] |
193 | [email protected] |
194 | [email protected] "foo" |
194 | [email protected] "(" |
195 | [email protected] |
195 | [email protected] ")" |
196 | [email protected] "(" |
196 | [email protected] " " |
197 | [email protected] ")" |
197 | [email protected] |
198 | [email protected] " " |
198 | [email protected] "{" |
199 | [email protected] |
199 | [email protected] "}" |
200 | [email protected] "{" |
200 | "#]], |
201 | [email protected] "}" |
| |
202 | "# |
| |
203 | .trim(), |
| |
204 | syn.trim() |
| |
205 | ); |
201 | ); |
206 | |
202 | |
207 | let (analysis, range) = fixture::range( |
203 | check_range( |
208 | r#"fn test() { |
204 | r#" |
| |
205 | fn test() { |
209 | $0assert!(" |
206 | $0assert!(" |
210 | fn foo() { |
207 | fn foo() { |
211 | } |
208 | } |
212 | ", "");$0 |
209 | ", "");$0 |
213 | }"# |
210 | }"#, |
214 | .trim(), |
211 | expect![[r#" |
215 | ); |
212 | [email protected] |
216 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); |
213 | [email protected] |
217 | |
214 | [email protected] |
218 | assert_eq_text!( |
215 | [email protected] |
219 | r#" |
216 | [email protected] |
220 | [email protected] |
217 | [email protected] "assert" |
221 | [email protected] |
218 | [email protected] "!" |
222 | [email protected] |
219 | [email protected] |
223 | [email protected] |
220 | [email protected] "(" |
224 | [email protected] |
221 | [email protected] "\"\n fn foo() {\n ..." |
225 | [email protected] "assert" |
222 | [email protected] "," |
226 | [email protected] "!" |
223 | [email protected] " " |
227 | [email protected] |
224 | [email protected] "\"\"" |
228 | [email protected] "(" |
225 | [email protected] ")" |
229 | [email protected] "\"\n fn foo() {\n ..." |
226 | [email protected] ";" |
230 | [email protected] "," |
227 | "#]], |
231 | [email protected] " " |
| |
232 | [email protected] "\"\"" |
| |
233 | [email protected] ")" |
| |
234 | [email protected] ";" |
| |
235 | "# |
| |
236 | .trim(), |
| |
237 | syn.trim() |
| |
238 | ); |
228 | ); |
239 | } |
229 | } |
240 | |
230 | |
241 | #[test] |
231 | #[test] |
242 | fn test_syntax_tree_inside_string() { |
232 | fn test_syntax_tree_inside_string() { |
243 | let (analysis, range) = fixture::range( |
233 | check_range( |
244 | r#"fn test() { |
234 | r#"fn test() { |
245 | assert!(" |
235 | assert!(" |
246 | $0fn foo() { |
236 | $0fn foo() { |
@@ -248,33 +238,27 @@ $0fn foo() { |
248 | fn bar() { |
238 | fn bar() { |
249 | } |
239 | } |
250 | ", ""); |
240 | ", ""); |
251 | }"# |
241 | }"#, |
252 | .trim(), |
242 | expect![[r#" |
253 | ); |
243 | [email protected] |
254 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); |
244 | [email protected] |
255 | assert_eq_text!( |
245 | [email protected] "fn" |
256 | r#" |
246 | [email protected] " " |
257 | [email protected] |
247 | [email protected] |
258 | [email protected] |
248 | [email protected] "foo" |
259 | [email protected] "fn" |
249 | [email protected] |
260 | [email protected] " " |
250 | [email protected] "(" |
261 | [email protected] |
251 | [email protected] ")" |
262 | [email protected] "foo" |
252 | [email protected] " " |
263 | [email protected] |
253 | [email protected] |
264 | [email protected] "(" |
254 | [email protected] "{" |
265 | [email protected] ")" |
255 | [email protected] "\n" |
266 | [email protected] " " |
256 | [email protected] "}" |
267 | [email protected] |
257 | "#]], |
268 | [email protected] "{" |
| |
269 | [email protected] "\n" |
| |
270 | [email protected] "}" |
| |
271 | "# |
| |
272 | .trim(), |
| |
273 | syn.trim() |
| |
274 | ); |
258 | ); |
275 | |
259 | |
276 | // With a raw string |
260 | // With a raw string |
277 | let (analysis, range) = fixture::range( |
261 | check_range( |
278 | r###"fn test() { |
262 | r###"fn test() { |
279 | assert!(r#" |
263 | assert!(r#" |
280 | $0fn foo() { |
264 | $0fn foo() { |
@@ -282,76 +266,64 @@ $0fn foo() { |
282 | fn bar() { |
266 | fn bar() { |
283 | } |
267 | } |
284 | "#, ""); |
268 | "#, ""); |
285 | }"### |
269 | }"###, |
286 | .trim(), |
270 | expect![[r#" |
287 | ); |
271 | [email protected] |
288 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); |
272 | [email protected] |
289 | assert_eq_text!( |
273 | [email protected] "fn" |
290 | r#" |
274 | [email protected] " " |
291 | [email protected] |
275 | [email protected] |
292 | [email protected] |
276 | [email protected] "foo" |
293 | [email protected] "fn" |
277 | [email protected] |
294 | [email protected] " " |
278 | [email protected] "(" |
295 | [email protected] |
279 | [email protected] ")" |
296 | [email protected] "foo" |
280 | [email protected] " " |
297 | [email protected] |
281 | [email protected] |
298 | [email protected] "(" |
282 | [email protected] "{" |
299 | [email protected] ")" |
283 | [email protected] "\n" |
300 | [email protected] " " |
284 | [email protected] "}" |
301 | [email protected] |
285 | "#]], |
302 | [email protected] "{" |
| |
303 | [email protected] "\n" |
| |
304 | [email protected] "}" |
| |
305 | "# |
| |
306 | .trim(), |
| |
307 | syn.trim() |
| |
308 | ); |
286 | ); |
309 | |
287 | |
310 | // With a raw string |
288 | // With a raw string |
311 | let (analysis, range) = fixture::range( |
289 | check_range( |
312 | r###"fn test() { |
290 | r###"fn test() { |
313 | assert!(r$0#" |
291 | assert!(r$0#" |
314 | fn foo() { |
292 | fn foo() { |
315 | } |
293 | } |
316 | fn bar() { |
294 | fn bar() { |
317 | }"$0#, ""); |
295 | }"$0#, ""); |
318 | }"### |
296 | }"###, |
319 | .trim(), |
297 | expect![[r#" |
320 | ); |
298 | [email protected] |
321 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); |
299 | [email protected] |
322 | assert_eq_text!( |
300 | [email protected] "fn" |
323 | r#" |
301 | [email protected] " " |
324 | [email protected] |
302 | [email protected] |
325 | [email protected] |
303 | [email protected] "foo" |
326 | [email protected] "fn" |
304 | [email protected] |
327 | [email protected] " " |
305 | [email protected] "(" |
328 | [email protected] |
306 | [email protected] ")" |
329 | [email protected] "foo" |
307 | [email protected] " " |
330 | [email protected] |
308 | [email protected] |
331 | [email protected] "(" |
309 | [email protected] "{" |
332 | [email protected] ")" |
310 | [email protected] "\n" |
333 | [email protected] " " |
311 | [email protected] "}" |
334 | [email protected] |
312 | [email protected] "\n" |
335 | [email protected] "{" |
313 | [email protected] |
336 | [email protected] "\n" |
314 | [email protected] "fn" |
337 | [email protected] "}" |
315 | [email protected] " " |
338 | [email protected] "\n" |
316 | [email protected] |
339 | [email protected] |
317 | [email protected] "bar" |
340 | [email protected] "fn" |
318 | [email protected] |
341 | [email protected] " " |
319 | [email protected] "(" |
342 | [email protected] |
320 | [email protected] ")" |
343 | [email protected] "bar" |
321 | [email protected] " " |
344 | [email protected] |
322 | [email protected] |
345 | [email protected] "(" |
323 | [email protected] "{" |
346 | [email protected] ")" |
324 | [email protected] "\n" |
347 | [email protected] " " |
325 | [email protected] "}" |
348 | [email protected] |
326 | "#]], |
349 | [email protected] "{" |
| |
350 | [email protected] "\n" |
| |
351 | [email protected] "}" |
| |
352 | "# |
| |
353 | .trim(), |
| |
354 | syn.trim() |
| |
355 | ); |
327 | ); |
356 | } |
328 | } |
357 | } |
329 | } |
|