diff options
Diffstat (limited to 'crates/ra_ide_api/tests/test/main.rs')
-rw-r--r-- | crates/ra_ide_api/tests/test/main.rs | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs index 7d1695cfd..4126bd160 100644 --- a/crates/ra_ide_api/tests/test/main.rs +++ b/crates/ra_ide_api/tests/test/main.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | use insta::assert_debug_snapshot_matches; | 1 | use insta::assert_debug_snapshot_matches; |
2 | use ra_ide_api::{ | 2 | use ra_ide_api::{ |
3 | mock_analysis::{single_file, single_file_with_position, MockAnalysis}, | 3 | mock_analysis::{single_file, single_file_with_position, MockAnalysis}, |
4 | AnalysisChange, CrateGraph, FileId, Query, | 4 | AnalysisChange, CrateGraph, FileId, Query, NavigationTarget, |
5 | }; | 5 | }; |
6 | use ra_syntax::TextRange; | 6 | use ra_syntax::{TextRange, SmolStr}; |
7 | 7 | ||
8 | #[test] | 8 | #[test] |
9 | fn test_unresolved_module_diagnostic() { | 9 | fn test_unresolved_module_diagnostic() { |
@@ -49,6 +49,11 @@ fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { | |||
49 | analysis.find_all_refs(position).unwrap() | 49 | analysis.find_all_refs(position).unwrap() |
50 | } | 50 | } |
51 | 51 | ||
52 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { | ||
53 | let (analysis, _) = single_file(text); | ||
54 | analysis.symbol_search(Query::new(query.into())).unwrap() | ||
55 | } | ||
56 | |||
52 | #[test] | 57 | #[test] |
53 | fn test_find_all_refs_for_local() { | 58 | fn test_find_all_refs_for_local() { |
54 | let code = r#" | 59 | let code = r#" |
@@ -91,6 +96,55 @@ fn test_find_all_refs_for_fn_param() { | |||
91 | } | 96 | } |
92 | 97 | ||
93 | #[test] | 98 | #[test] |
99 | fn test_world_symbols_with_no_container() { | ||
100 | { | ||
101 | let code = r#" | ||
102 | enum FooInner { } | ||
103 | "#; | ||
104 | |||
105 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
106 | |||
107 | let s = symbols.pop().unwrap(); | ||
108 | |||
109 | assert_eq!(s.name(), "FooInner"); | ||
110 | assert!(s.container_name().is_none()); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | #[test] | ||
115 | fn test_world_symbols_include_container_name() { | ||
116 | { | ||
117 | let code = r#" | ||
118 | fn foo() { | ||
119 | enum FooInner { } | ||
120 | } | ||
121 | "#; | ||
122 | |||
123 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
124 | |||
125 | let s = symbols.pop().unwrap(); | ||
126 | |||
127 | assert_eq!(s.name(), "FooInner"); | ||
128 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
129 | } | ||
130 | |||
131 | { | ||
132 | let code = r#" | ||
133 | mod foo { | ||
134 | struct FooInner; | ||
135 | } | ||
136 | "#; | ||
137 | |||
138 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
139 | |||
140 | let s = symbols.pop().unwrap(); | ||
141 | |||
142 | assert_eq!(s.name(), "FooInner"); | ||
143 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | #[test] | ||
94 | #[ignore] | 148 | #[ignore] |
95 | fn world_symbols_include_stuff_from_macros() { | 149 | fn world_symbols_include_stuff_from_macros() { |
96 | let (analysis, _) = single_file( | 150 | let (analysis, _) = single_file( |