aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/tests
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-02-12 19:47:51 +0000
committerVille Penttinen <[email protected]>2019-02-12 20:06:14 +0000
commitdd6307ddc4535bef09e2b14caff5acfaeb88891e (patch)
tree4e1511826adb09561572ed8eb405f0ad8d84f42a /crates/ra_ide_api/tests
parent61324a845bde0959c1f9ac86ce31d022812f4c21 (diff)
Add support for container_name in workspace/symbol query
Diffstat (limited to 'crates/ra_ide_api/tests')
-rw-r--r--crates/ra_ide_api/tests/test/main.rs58
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 @@
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,55 @@ fn test_find_all_refs_for_fn_param() {
91} 96}
92 97
93#[test] 98#[test]
99fn 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]
115fn 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]
95fn world_symbols_include_stuff_from_macros() { 149fn world_symbols_include_stuff_from_macros() {
96 let (analysis, _) = single_file( 150 let (analysis, _) = single_file(