aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/tests/test/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/tests/test/main.rs')
-rw-r--r--crates/ra_ide_api/tests/test/main.rs52
1 files changed, 50 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..4cf842452 100644
--- a/crates/ra_ide_api/tests/test/main.rs
+++ b/crates/ra_ide_api/tests/test/main.rs
@@ -1,9 +1,9 @@
1use insta::assert_debug_snapshot_matches; 1use insta::assert_debug_snapshot_matches;
2use ra_ide_api::{ 2use 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};
6use ra_syntax::TextRange; 6use ra_syntax::{TextRange, SmolStr};
7 7
8#[test] 8#[test]
9fn test_unresolved_module_diagnostic() { 9fn 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
52fn 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]
53fn test_find_all_refs_for_local() { 58fn test_find_all_refs_for_local() {
54 let code = r#" 59 let code = r#"
@@ -91,6 +96,49 @@ fn test_find_all_refs_for_fn_param() {
91} 96}
92 97
93#[test] 98#[test]
99fn test_world_symbols_with_no_container() {
100 let code = r#"
101 enum FooInner { }
102 "#;
103
104 let mut symbols = get_symbols_matching(code, "FooInner");
105
106 let s = symbols.pop().unwrap();
107
108 assert_eq!(s.name(), "FooInner");
109 assert!(s.container_name().is_none());
110}
111
112#[test]
113fn test_world_symbols_include_container_name() {
114 let code = r#"
115fn foo() {
116 enum FooInner { }
117}
118 "#;
119
120 let mut symbols = get_symbols_matching(code, "FooInner");
121
122 let s = symbols.pop().unwrap();
123
124 assert_eq!(s.name(), "FooInner");
125 assert_eq!(s.container_name(), Some(&SmolStr::new("foo")));
126
127 let code = r#"
128mod foo {
129 struct FooInner;
130}
131 "#;
132
133 let mut symbols = get_symbols_matching(code, "FooInner");
134
135 let s = symbols.pop().unwrap();
136
137 assert_eq!(s.name(), "FooInner");
138 assert_eq!(s.container_name(), Some(&SmolStr::new("foo")));
139}
140
141#[test]
94#[ignore] 142#[ignore]
95fn world_symbols_include_stuff_from_macros() { 143fn world_symbols_include_stuff_from_macros() {
96 let (analysis, _) = single_file( 144 let (analysis, _) = single_file(