aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-23 23:48:38 +0100
committerAleksey Kladov <[email protected]>2020-06-23 23:48:38 +0100
commitd016cb486738c1ab2574a322924183fa8a870b06 (patch)
tree841871b66bc008a18a5a1053f5a33415c3a54ad9 /crates/ra_hir_def/src
parente5101ae150db5faa7ddf8393e375032ef371f5e5 (diff)
Use only one code-path for parsing fixtures
This removes leading newlines everywhere, shifting all ranges in tests by one
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/body/scope.rs93
1 files changed, 49 insertions, 44 deletions
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs
index 661f00407..0b74199d9 100644
--- a/crates/ra_hir_def/src/body/scope.rs
+++ b/crates/ra_hir_def/src/body/scope.rs
@@ -189,20 +189,22 @@ mod tests {
189 } 189 }
190 190
191 fn do_check(ra_fixture: &str, expected: &[&str]) { 191 fn do_check(ra_fixture: &str, expected: &[&str]) {
192 let (off, code) = extract_offset(ra_fixture); 192 let (offset, code) = extract_offset(ra_fixture);
193 let code = { 193 let code = {
194 let mut buf = String::new(); 194 let mut buf = String::new();
195 let off: usize = off.into(); 195 let off: usize = offset.into();
196 buf.push_str(&code[..off]); 196 buf.push_str(&code[..off]);
197 buf.push_str("marker"); 197 buf.push_str("<|>marker");
198 buf.push_str(&code[off..]); 198 buf.push_str(&code[off..]);
199 buf 199 buf
200 }; 200 };
201 201
202 let (db, file_id) = TestDB::with_single_file(&code); 202 let (db, position) = TestDB::with_position(&code);
203 let file_id = position.file_id;
204 let offset = position.offset;
203 205
204 let file_syntax = db.parse(file_id).syntax_node(); 206 let file_syntax = db.parse(file_id).syntax_node();
205 let marker: ast::PathExpr = find_node_at_offset(&file_syntax, off).unwrap(); 207 let marker: ast::PathExpr = find_node_at_offset(&file_syntax, offset).unwrap();
206 let function = find_function(&db, file_id); 208 let function = find_function(&db, file_id);
207 209
208 let scopes = db.expr_scopes(function.into()); 210 let scopes = db.expr_scopes(function.into());
@@ -302,27 +304,28 @@ mod tests {
302 fn test_bindings_after_at() { 304 fn test_bindings_after_at() {
303 do_check( 305 do_check(
304 r" 306 r"
305 fn foo() { 307fn foo() {
306 match Some(()) { 308 match Some(()) {
307 opt @ Some(unit) => { 309 opt @ Some(unit) => {
308 <|> 310 <|>
309 } 311 }
310 _ => {} 312 _ => {}
311 } 313 }
312 }", 314}
315",
313 &["opt", "unit"], 316 &["opt", "unit"],
314 ); 317 );
315 } 318 }
316 319
317 fn do_check_local_name(code: &str, expected_offset: u32) { 320 fn do_check_local_name(ra_fixture: &str, expected_offset: u32) {
318 let (off, code) = extract_offset(code); 321 let (db, position) = TestDB::with_position(ra_fixture);
319 322 let file_id = position.file_id;
320 let (db, file_id) = TestDB::with_single_file(&code); 323 let offset = position.offset;
321 324
322 let file = db.parse(file_id).ok().unwrap(); 325 let file = db.parse(file_id).ok().unwrap();
323 let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into()) 326 let expected_name = find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into())
324 .expect("failed to find a name at the target offset"); 327 .expect("failed to find a name at the target offset");
325 let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); 328 let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), offset).unwrap();
326 329
327 let function = find_function(&db, file_id); 330 let function = find_function(&db, file_id);
328 331
@@ -350,15 +353,16 @@ mod tests {
350 fn test_resolve_local_name() { 353 fn test_resolve_local_name() {
351 do_check_local_name( 354 do_check_local_name(
352 r#" 355 r#"
353 fn foo(x: i32, y: u32) { 356fn foo(x: i32, y: u32) {
354 { 357 {
355 let z = x * 2; 358 let z = x * 2;
356 } 359 }
357 { 360 {
358 let t = x<|> * 3; 361 let t = x<|> * 3;
359 } 362 }
360 }"#, 363}
361 21, 364"#,
365 7,
362 ); 366 );
363 } 367 }
364 368
@@ -366,10 +370,11 @@ mod tests {
366 fn test_resolve_local_name_declaration() { 370 fn test_resolve_local_name_declaration() {
367 do_check_local_name( 371 do_check_local_name(
368 r#" 372 r#"
369 fn foo(x: String) { 373fn foo(x: String) {
370 let x : &str = &x<|>; 374 let x : &str = &x<|>;
371 }"#, 375}
372 21, 376"#,
377 7,
373 ); 378 );
374 } 379 }
375 380
@@ -377,12 +382,12 @@ mod tests {
377 fn test_resolve_local_name_shadow() { 382 fn test_resolve_local_name_shadow() {
378 do_check_local_name( 383 do_check_local_name(
379 r" 384 r"
380 fn foo(x: String) { 385fn foo(x: String) {
381 let x : &str = &x; 386 let x : &str = &x;
382 x<|> 387 x<|>
383 } 388}
384 ", 389",
385 53, 390 28,
386 ); 391 );
387 } 392 }
388 393
@@ -390,13 +395,13 @@ mod tests {
390 fn ref_patterns_contribute_bindings() { 395 fn ref_patterns_contribute_bindings() {
391 do_check_local_name( 396 do_check_local_name(
392 r" 397 r"
393 fn foo() { 398fn foo() {
394 if let Some(&from) = bar() { 399 if let Some(&from) = bar() {
395 from<|>; 400 from<|>;
396 } 401 }
397 } 402}
398 ", 403",
399 53, 404 28,
400 ); 405 );
401 } 406 }
402 407