aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-08 21:48:54 +0000
committerAleksey Kladov <[email protected]>2019-01-08 21:48:54 +0000
commit8f93e7b9a4f99a458bf03c7ef9871060fa8f2cf9 (patch)
treeb8d3864cd7c369280440438ec7109768963f0ab5 /crates/ra_hir
parent46f74e33ca53a7897e9020d3de75cc76a6b89d79 (diff)
remove duplication in tests
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/nameres/tests.rs88
1 files changed, 33 insertions, 55 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index c511c40b2..ac96bea37 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -322,9 +322,33 @@ fn reexport_across_crates() {
322 ); 322 );
323} 323}
324 324
325fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) {
326 let (mut db, pos) = MockDatabase::with_position(initial);
327 let source_root = db.file_source_root(pos.file_id);
328 {
329 let events = db.log_executed(|| {
330 db.item_map(source_root).unwrap();
331 });
332 assert!(format!("{:?}", events).contains("item_map"))
333 }
334 db.query_mut(ra_db::FileTextQuery)
335 .set(pos.file_id, Arc::new(file_change.to_string()));
336
337 {
338 let events = db.log_executed(|| {
339 db.item_map(source_root).unwrap();
340 });
341 assert!(
342 !format!("{:?}", events).contains("item_map"),
343 "{:#?}",
344 events
345 )
346 }
347}
348
325#[test] 349#[test]
326fn typing_inside_a_function_should_not_invalidate_item_map() { 350fn typing_inside_a_function_should_not_invalidate_item_map() {
327 let (mut db, pos) = MockDatabase::with_position( 351 check_item_map_is_not_recomputed(
328 " 352 "
329 //- /lib.rs 353 //- /lib.rs
330 mod foo; 354 mod foo;
@@ -342,42 +366,19 @@ fn typing_inside_a_function_should_not_invalidate_item_map() {
342 } 366 }
343 } 367 }
344 ", 368 ",
345 ); 369 "
346 let source_root = db.file_source_root(pos.file_id);
347 {
348 let events = db.log_executed(|| {
349 db.item_map(source_root).unwrap();
350 });
351 assert!(format!("{:?}", events).contains("item_map"))
352 }
353
354 let new_text = "
355 salsa::query_group! { 370 salsa::query_group! {
356 trait Baz { 371 trait Baz {
357 fn foo() -> i32 { 92 } 372 fn foo() -> i32 { 92 }
358 } 373 }
359 } 374 }
360 " 375 ",
361 .to_string(); 376 );
362
363 db.query_mut(ra_db::FileTextQuery)
364 .set(pos.file_id, Arc::new(new_text));
365
366 {
367 let events = db.log_executed(|| {
368 db.item_map(source_root).unwrap();
369 });
370 assert!(
371 !format!("{:?}", events).contains("item_map"),
372 "{:#?}",
373 events
374 )
375 }
376} 377}
377 378
378#[test] 379#[test]
379fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() { 380fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() {
380 let (mut db, pos) = MockDatabase::with_position( 381 check_item_map_is_not_recomputed(
381 " 382 "
382 //- /lib.rs 383 //- /lib.rs
383 mod foo;<|> 384 mod foo;<|>
@@ -392,36 +393,13 @@ fn typing_inside_a_function_inside_a_macro_should_not_invalidate_item_map() {
392 393
393 //- /foo/bar.rs 394 //- /foo/bar.rs
394 pub struct Baz; 395 pub struct Baz;
395 ", 396 ",
396 ); 397 "
397 let source_root = db.file_source_root(pos.file_id);
398 {
399 let events = db.log_executed(|| {
400 db.item_map(source_root).unwrap();
401 });
402 assert!(format!("{:?}", events).contains("item_map"))
403 }
404
405 let new_text = "
406 mod foo; 398 mod foo;
407 399
408 use crate::foo::bar::Baz; 400 use crate::foo::bar::Baz;
409 401
410 fn foo() -> i32 { 92 } 402 fn foo() -> i32 { 92 }
411 " 403 ",
412 .to_string(); 404 );
413
414 db.query_mut(ra_db::FileTextQuery)
415 .set(pos.file_id, Arc::new(new_text));
416
417 {
418 let events = db.log_executed(|| {
419 db.item_map(source_root).unwrap();
420 });
421 assert!(
422 !format!("{:?}", events).contains("item_map"),
423 "{:#?}",
424 events
425 )
426 }
427} 405}