From c749fe223bf5a41709a4bc91d0f56dafc4201658 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Jun 2020 11:31:30 +0200 Subject: Remove duplication --- crates/ra_ide/src/call_info.rs | 6 ++--- crates/ra_ide/src/completion/test_utils.rs | 6 ++--- crates/ra_ide/src/extend_selection.rs | 4 ++-- crates/ra_ide/src/hover.rs | 36 +++++++++++++++--------------- crates/ra_ide/src/mock_analysis.rs | 5 ----- crates/ra_ide/src/references.rs | 4 ++-- crates/ra_ide/src/references/rename.rs | 10 ++++----- crates/ra_ide/src/typing/on_enter.rs | 4 ++-- 8 files changed, 34 insertions(+), 41 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index aa039e6fc..a6bdf1c9d 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -215,7 +215,7 @@ impl CallInfo { mod tests { use test_utils::mark; - use crate::mock_analysis::single_file_with_position; + use crate::mock_analysis::analysis_and_position; use super::*; @@ -231,7 +231,7 @@ mod tests { } fn call_info_helper(text: &str) -> Option { - let (analysis, position) = single_file_with_position(text); + let (analysis, position) = analysis_and_position(text); analysis.call_info(position).unwrap() } @@ -530,7 +530,7 @@ By default this method stops actor's `Context`."# #[test] fn call_info_bad_offset() { mark::check!(call_info_bad_offset); - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( r#"fn foo(x: u32, y: u32) -> u32 {x + y} fn bar() { foo <|> (3, ); }"#, ); diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index 1e16a43ca..a1b7c1193 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs @@ -2,7 +2,7 @@ use crate::{ completion::{completion_item::CompletionKind, CompletionConfig}, - mock_analysis::{analysis_and_position, single_file_with_position}, + mock_analysis::analysis_and_position, CompletionItem, }; use hir::Semantics; @@ -33,7 +33,7 @@ fn get_all_completion_items(code: &str, options: &CompletionConfig) -> Vec bool) { - let (analysis, pos) = single_file_with_position(code); + let (analysis, pos) = analysis_and_position(code); analysis .with_db(|db| { let sema = Semantics::new(db); diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index cb6b1a40d..8a6b3ea99 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -315,12 +315,12 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment { #[cfg(test)] mod tests { - use crate::mock_analysis::single_file_with_position; + use crate::mock_analysis::analysis_and_position; use super::*; fn do_check(before: &str, afters: &[&str]) { - let (analysis, position) = single_file_with_position(&before); + let (analysis, position) = analysis_and_position(&before); let before = analysis.file_text(position.file_id).unwrap(); let range = TextRange::empty(position.offset); let mut frange = FileRange { file_id: position.file_id, range }; diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 9660fd2d3..c3e36a387 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -399,7 +399,7 @@ mod tests { use ra_db::FileLoader; use ra_syntax::TextRange; - use crate::mock_analysis::{analysis_and_position, single_file_with_position}; + use crate::mock_analysis::analysis_and_position; fn trim_markup(s: &str) -> &str { s.trim_start_matches("```rust\n").trim_end_matches("\n```") @@ -442,7 +442,7 @@ mod tests { #[test] fn hover_shows_type_of_an_expression() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( r#" pub fn foo() -> u32 { 1 } @@ -641,7 +641,7 @@ fn main() { #[test] fn hover_some() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " enum Option { Some(T) } use Option::Some; @@ -654,7 +654,7 @@ fn main() { let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(trim_markup_opt(hover.info.first()), Some("Option\n```\n\n```rust\nSome")); - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " enum Option { Some(T) } use Option::Some; @@ -720,21 +720,21 @@ The Some variant #[test] fn hover_for_local_variable() { - let (analysis, position) = single_file_with_position("fn func(foo: i32) { fo<|>o; }"); + let (analysis, position) = analysis_and_position("fn func(foo: i32) { fo<|>o; }"); let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); } #[test] fn hover_for_local_variable_pat() { - let (analysis, position) = single_file_with_position("fn func(fo<|>o: i32) {}"); + let (analysis, position) = analysis_and_position("fn func(fo<|>o: i32) {}"); let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); } #[test] fn hover_local_var_edge() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " fn func(foo: i32) { if true { <|>foo; }; } ", @@ -745,14 +745,14 @@ fn func(foo: i32) { if true { <|>foo; }; } #[test] fn hover_for_param_edge() { - let (analysis, position) = single_file_with_position("fn func(<|>foo: i32) {}"); + let (analysis, position) = analysis_and_position("fn func(<|>foo: i32) {}"); let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); } #[test] fn test_hover_infer_associated_method_result() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " struct Thing { x: u32 } @@ -773,7 +773,7 @@ fn func(foo: i32) { if true { <|>foo; }; } #[test] fn test_hover_infer_associated_method_exact() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " mod wrapper { struct Thing { x: u32 } @@ -799,7 +799,7 @@ fn func(foo: i32) { if true { <|>foo; }; } #[test] fn test_hover_infer_associated_const_in_pattern() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " struct X; impl X { @@ -821,7 +821,7 @@ fn func(foo: i32) { if true { <|>foo; }; } #[test] fn test_hover_self() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " struct Thing { x: u32 } impl Thing { @@ -835,7 +835,7 @@ fn func(foo: i32) { if true { <|>foo; }; } assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); /* FIXME: revive these tests - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " struct Thing { x: u32 } impl Thing { @@ -849,7 +849,7 @@ fn func(foo: i32) { if true { <|>foo; }; } let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " enum Thing { A } impl Thing { @@ -862,7 +862,7 @@ fn func(foo: i32) { if true { <|>foo; }; } let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " enum Thing { A } impl Thing { @@ -878,7 +878,7 @@ fn func(foo: i32) { if true { <|>foo; }; } #[test] fn test_hover_shadowing_pat() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " fn x() {} @@ -894,7 +894,7 @@ fn func(foo: i32) { if true { <|>foo; }; } #[test] fn test_hover_macro_invocation() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " macro_rules! foo { () => {} @@ -911,7 +911,7 @@ fn func(foo: i32) { if true { <|>foo; }; } #[test] fn test_hover_tuple_field() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " struct TS(String, i32<|>); ", diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index f568d6baa..e99c2b0a3 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -221,11 +221,6 @@ pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) { (mock.analysis(), file_id) } -/// Creates analysis for a single file, returns position marked with <|>. -pub fn single_file_with_position(ra_fixture: &str) -> (Analysis, FilePosition) { - analysis_and_position(ra_fixture) -} - /// Creates analysis for a single file, returns range marked with a pair of <|>. pub fn single_file_with_range(ra_fixture: &str) -> (Analysis, FileRange) { let mut mock = MockAnalysis::new(); diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 50929bb72..3433fdae3 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -191,7 +191,7 @@ fn get_struct_def_name_for_struct_literal_search( #[cfg(test)] mod tests { use crate::{ - mock_analysis::{analysis_and_position, single_file_with_position, MockAnalysis}, + mock_analysis::{analysis_and_position, MockAnalysis}, Declaration, Reference, ReferenceSearchResult, SearchScope, }; @@ -653,7 +653,7 @@ fn main() { } fn get_all_refs(ra_fixture: &str) -> ReferenceSearchResult { - let (analysis, position) = single_file_with_position(ra_fixture); + let (analysis, position) = analysis_and_position(ra_fixture); analysis.find_all_refs(position, None).unwrap().unwrap() } diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 91545e025..7ebc0adcf 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -271,12 +271,10 @@ fn rename_reference( mod tests { use insta::assert_debug_snapshot; use ra_text_edit::TextEditBuilder; + use stdx::trim_indent; use test_utils::{assert_eq_text, mark}; - use crate::{ - mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, - }; - use stdx::trim_indent; + use crate::{mock_analysis::analysis_and_position, FileId}; #[test] fn test_rename_to_underscore() { @@ -310,7 +308,7 @@ mod tests { #[test] fn test_rename_to_invalid_identifier() { - let (analysis, position) = single_file_with_position( + let (analysis, position) = analysis_and_position( " fn main() { let i<|> = 1; @@ -1056,7 +1054,7 @@ pub mod foo<|>; fn test_rename(ra_fixture_before: &str, new_name: &str, ra_fixture_after: &str) { let ra_fixture_after = &trim_indent(ra_fixture_after); - let (analysis, position) = single_file_with_position(ra_fixture_before); + let (analysis, position) = analysis_and_position(ra_fixture_before); let source_change = analysis.rename(position, new_name).unwrap(); let mut text_edit_builder = TextEditBuilder::default(); let mut file_id: Option = None; diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index 50adae8bb..2faaa8ff0 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs @@ -77,11 +77,11 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option { mod tests { use test_utils::assert_eq_text; - use crate::mock_analysis::single_file_with_position; + use crate::mock_analysis::analysis_and_position; use stdx::trim_indent; fn apply_on_enter(before: &str) -> Option { - let (analysis, position) = single_file_with_position(&before); + let (analysis, position) = analysis_and_position(&before); let result = analysis.on_enter(position).unwrap()?; let mut actual = analysis.file_text(position.file_id).unwrap().to_string(); -- cgit v1.2.3