From da32463cbf8dc32229eb13844c71a40df2d3b77e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 5 Jan 2019 19:41:43 +0300 Subject: inline goto_defention tests --- crates/ra_analysis/src/goto_defenition.rs | 58 ++++++++++++++++++++++++++++++ crates/ra_analysis/src/lib.rs | 7 ---- crates/ra_analysis/tests/test/main.rs | 59 ------------------------------- 3 files changed, 58 insertions(+), 66 deletions(-) (limited to 'crates/ra_analysis') diff --git a/crates/ra_analysis/src/goto_defenition.rs b/crates/ra_analysis/src/goto_defenition.rs index 91de7ef65..08d1809ee 100644 --- a/crates/ra_analysis/src/goto_defenition.rs +++ b/crates/ra_analysis/src/goto_defenition.rs @@ -78,3 +78,61 @@ fn name_defenition( } Ok(None) } + +#[cfg(test)] +mod tests { + use test_utils::assert_eq_dbg; + use crate::mock_analysis::analysis_and_position; + + #[test] + fn goto_defenition_works_in_items() { + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + struct Foo; + enum E { X(Foo<|>) } + ", + ); + + let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); + assert_eq_dbg( + r#"[NavigationTarget { file_id: FileId(1), name: "Foo", + kind: STRUCT_DEF, range: [0; 11), + ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]"#, + &symbols, + ); + } + + #[test] + fn goto_defenition_works_for_module_declaration() { + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + mod <|>foo; + //- /foo.rs + // empty + ", + ); + + let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); + assert_eq_dbg( + r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, + &symbols, + ); + + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + mod <|>foo; + //- /foo/mod.rs + // empty + ", + ); + + let symbols = analysis.goto_defenition(pos).unwrap().unwrap(); + assert_eq_dbg( + r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#, + &symbols, + ); + } +} diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 0dac9f268..13527e628 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -399,13 +399,6 @@ impl Analysis { ) -> Cancelable>> { goto_defenition::goto_defenition(&*self.db, position) } - // /// Resolves reference to definition, but does not gurantee correctness. - // pub fn approximately_resolve_symbol( - // &self, - // position: FilePosition, - // ) -> Cancelable> { - // self.db.approximately_resolve_symbol(position) - // } /// Finds all usages of the reference at point. pub fn find_all_refs(&self, position: FilePosition) -> Cancelable> { self.db.find_all_refs(position) diff --git a/crates/ra_analysis/tests/test/main.rs b/crates/ra_analysis/tests/test/main.rs index beeae1e19..e15035304 100644 --- a/crates/ra_analysis/tests/test/main.rs +++ b/crates/ra_analysis/tests/test/main.rs @@ -14,65 +14,6 @@ fn get_signature(text: &str) -> (FnSignatureInfo, Option) { analysis.resolve_callable(position).unwrap().unwrap() } -#[test] -fn approximate_resolve_works_in_items() { - let (analysis, pos) = analysis_and_position( - " - //- /lib.rs - struct Foo; - enum E { X(Foo<|>) } - ", - ); - - let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap(); - assert_eq_dbg( - r#"ReferenceResolution { - reference_range: [23; 26), - resolves_to: [NavigationTarget { file_id: FileId(1), name: "Foo", kind: STRUCT_DEF, range: [0; 11), ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }] - }"#, - &symbols, - ); -} - -#[test] -fn test_resolve_module() { - let (analysis, pos) = analysis_and_position( - " - //- /lib.rs - mod <|>foo; - //- /foo.rs - // empty - ", - ); - - let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap(); - assert_eq_dbg( - r#"ReferenceResolution { - reference_range: [4; 7), - resolves_to: [NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }] - }"#, - &symbols, - ); - - let (analysis, pos) = analysis_and_position( - " - //- /lib.rs - mod <|>foo; - //- /foo/mod.rs - // empty - ", - ); - - let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap(); - assert_eq_dbg( - r#"ReferenceResolution { - reference_range: [4; 7), - resolves_to: [NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }] - }"#, - &symbols, - ); -} - #[test] fn test_unresolved_module_diagnostic() { let (analysis, file_id) = single_file("mod foo;"); -- cgit v1.2.3