aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs71
-rw-r--r--crates/ra_ide/src/lib.rs74
2 files changed, 71 insertions, 74 deletions
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 6dcb9415a..fd245705c 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -418,3 +418,74 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) ->
418 } 418 }
419 } 419 }
420} 420}
421
422#[cfg(test)]
423mod tests {
424 use expect::expect;
425
426 use crate::{mock_analysis::single_file, Query};
427
428 #[test]
429 fn test_nav_for_symbol() {
430 let (analysis, _) = single_file(
431 r#"
432enum FooInner { }
433fn foo() { enum FooInner { } }
434"#,
435 );
436
437 let navs = analysis.symbol_search(Query::new("FooInner".to_string())).unwrap();
438 expect![[r#"
439 [
440 NavigationTarget {
441 file_id: FileId(
442 1,
443 ),
444 full_range: 0..17,
445 focus_range: Some(
446 5..13,
447 ),
448 name: "FooInner",
449 kind: ENUM_DEF,
450 container_name: None,
451 description: Some(
452 "enum FooInner",
453 ),
454 docs: None,
455 },
456 NavigationTarget {
457 file_id: FileId(
458 1,
459 ),
460 full_range: 29..46,
461 focus_range: Some(
462 34..42,
463 ),
464 name: "FooInner",
465 kind: ENUM_DEF,
466 container_name: Some(
467 "foo",
468 ),
469 description: Some(
470 "enum FooInner",
471 ),
472 docs: None,
473 },
474 ]
475 "#]]
476 .assert_debug_eq(&navs);
477 }
478
479 #[test]
480 fn test_world_symbols_are_case_sensitive() {
481 let (analysis, _) = single_file(
482 r#"
483fn foo() {}
484struct Foo;
485"#,
486 );
487
488 let navs = analysis.symbol_search(Query::new("foo".to_string())).unwrap();
489 assert_eq!(navs.len(), 2)
490 }
491}
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 353f430ff..dc9192d42 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -526,77 +526,3 @@ fn analysis_is_send() {
526 fn is_send<T: Send>() {} 526 fn is_send<T: Send>() {}
527 is_send::<Analysis>(); 527 is_send::<Analysis>();
528} 528}
529
530#[cfg(test)]
531mod tests {
532 use crate::{display::NavigationTarget, mock_analysis::single_file, Query};
533 use ra_syntax::{
534 SmolStr,
535 SyntaxKind::{FN_DEF, STRUCT_DEF},
536 };
537
538 #[test]
539 fn test_world_symbols_with_no_container() {
540 let code = r#"
541 enum FooInner { }
542 "#;
543
544 let mut symbols = get_symbols_matching(code, "FooInner");
545
546 let s = symbols.pop().unwrap();
547
548 assert_eq!(s.name, "FooInner");
549 assert!(s.container_name.is_none());
550 }
551
552 #[test]
553 fn test_world_symbols_include_container_name() {
554 let code = r#"
555fn foo() {
556 enum FooInner { }
557}
558 "#;
559
560 let mut symbols = get_symbols_matching(code, "FooInner");
561
562 let s = symbols.pop().unwrap();
563
564 assert_eq!(s.name, "FooInner");
565 assert_eq!(s.container_name, Some(SmolStr::new("foo")));
566
567 let code = r#"
568mod foo {
569 struct FooInner;
570}
571 "#;
572
573 let mut symbols = get_symbols_matching(code, "FooInner");
574
575 let s = symbols.pop().unwrap();
576
577 assert_eq!(s.name, "FooInner");
578 assert_eq!(s.container_name, Some(SmolStr::new("foo")));
579 }
580
581 #[test]
582 fn test_world_symbols_are_case_sensitive() {
583 let code = r#"
584fn foo() {}
585
586struct Foo;
587 "#;
588
589 let symbols = get_symbols_matching(code, "Foo");
590
591 let fn_match = symbols.iter().find(|s| s.name == "foo").map(|s| s.kind);
592 let struct_match = symbols.iter().find(|s| s.name == "Foo").map(|s| s.kind);
593
594 assert_eq!(fn_match, Some(FN_DEF));
595 assert_eq!(struct_match, Some(STRUCT_DEF));
596 }
597
598 fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> {
599 let (analysis, _) = single_file(text);
600 analysis.symbol_search(Query::new(query.into())).unwrap()
601 }
602}