From e9cb818c2683e06153f013c3b8d03f7f2719eb02 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Jun 2020 11:05:47 +0200 Subject: Use fixtures more --- crates/ra_ide/src/typing/on_enter.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide/src/typing') diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index a40d8af9c..787e85ffd 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs @@ -75,18 +75,15 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option { #[cfg(test)] mod tests { - use test_utils::{assert_eq_text, extract_offset}; + use test_utils::assert_eq_text; - use crate::mock_analysis::single_file; - - use super::*; + use crate::mock_analysis::single_file_with_position; fn apply_on_enter(before: &str) -> Option { - let (offset, before) = extract_offset(before); - let (analysis, file_id) = single_file(&before); - let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?; + let (analysis, position) = single_file_with_position(&before); + let result = analysis.on_enter(position).unwrap()?; - let mut actual = before.to_string(); + let mut actual = analysis.file_text(position.file_id).unwrap().to_string(); result.apply(&mut actual); Some(actual) } -- cgit v1.2.3 From c6795fb83a850dde6ac0b08decf108c0c3aa452a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Jun 2020 11:29:43 +0200 Subject: More consistent usage of fixtures --- crates/ra_ide/src/typing/on_enter.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_ide/src/typing') diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index 787e85ffd..50adae8bb 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs @@ -78,6 +78,7 @@ mod tests { use test_utils::assert_eq_text; use crate::mock_analysis::single_file_with_position; + use stdx::trim_indent; fn apply_on_enter(before: &str) -> Option { let (analysis, position) = single_file_with_position(&before); @@ -89,6 +90,7 @@ mod tests { } fn do_check(ra_fixture_before: &str, ra_fixture_after: &str) { + let ra_fixture_after = &trim_indent(ra_fixture_after); let actual = apply_on_enter(ra_fixture_before).unwrap(); assert_eq_text!(ra_fixture_after, &actual); } -- cgit v1.2.3 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/typing/on_enter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/typing') 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