diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 013b960c1..5fb111a90 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -479,3 +479,77 @@ fn analysis_is_send() { | |||
479 | fn is_send<T: Send>() {} | 479 | fn is_send<T: Send>() {} |
480 | is_send::<Analysis>(); | 480 | is_send::<Analysis>(); |
481 | } | 481 | } |
482 | |||
483 | #[cfg(test)] | ||
484 | mod tests { | ||
485 | use crate::{display::NavigationTarget, mock_analysis::single_file, Query}; | ||
486 | use ra_syntax::{ | ||
487 | SmolStr, | ||
488 | SyntaxKind::{FN_DEF, STRUCT_DEF}, | ||
489 | }; | ||
490 | |||
491 | #[test] | ||
492 | fn test_world_symbols_with_no_container() { | ||
493 | let code = r#" | ||
494 | enum FooInner { } | ||
495 | "#; | ||
496 | |||
497 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
498 | |||
499 | let s = symbols.pop().unwrap(); | ||
500 | |||
501 | assert_eq!(s.name(), "FooInner"); | ||
502 | assert!(s.container_name().is_none()); | ||
503 | } | ||
504 | |||
505 | #[test] | ||
506 | fn test_world_symbols_include_container_name() { | ||
507 | let code = r#" | ||
508 | fn foo() { | ||
509 | enum FooInner { } | ||
510 | } | ||
511 | "#; | ||
512 | |||
513 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
514 | |||
515 | let s = symbols.pop().unwrap(); | ||
516 | |||
517 | assert_eq!(s.name(), "FooInner"); | ||
518 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
519 | |||
520 | let code = r#" | ||
521 | mod foo { | ||
522 | struct FooInner; | ||
523 | } | ||
524 | "#; | ||
525 | |||
526 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
527 | |||
528 | let s = symbols.pop().unwrap(); | ||
529 | |||
530 | assert_eq!(s.name(), "FooInner"); | ||
531 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
532 | } | ||
533 | |||
534 | #[test] | ||
535 | fn test_world_symbols_are_case_sensitive() { | ||
536 | let code = r#" | ||
537 | fn foo() {} | ||
538 | |||
539 | struct Foo; | ||
540 | "#; | ||
541 | |||
542 | let symbols = get_symbols_matching(code, "Foo"); | ||
543 | |||
544 | let fn_match = symbols.iter().find(|s| s.name() == "foo").map(|s| s.kind()); | ||
545 | let struct_match = symbols.iter().find(|s| s.name() == "Foo").map(|s| s.kind()); | ||
546 | |||
547 | assert_eq!(fn_match, Some(FN_DEF)); | ||
548 | assert_eq!(struct_match, Some(STRUCT_DEF)); | ||
549 | } | ||
550 | |||
551 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { | ||
552 | let (analysis, _) = single_file(text); | ||
553 | analysis.symbol_search(Query::new(query.into())).unwrap() | ||
554 | } | ||
555 | } | ||