From 58e77660deae23f0a2f5a7c42f52ec7cab707e57 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Thu, 21 Mar 2019 19:51:42 +0100 Subject: Move join_lines to ra_ide_api --- crates/ra_ide_api/src/test_utils.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 crates/ra_ide_api/src/test_utils.rs (limited to 'crates/ra_ide_api/src/test_utils.rs') diff --git a/crates/ra_ide_api/src/test_utils.rs b/crates/ra_ide_api/src/test_utils.rs new file mode 100644 index 000000000..bfac0fce3 --- /dev/null +++ b/crates/ra_ide_api/src/test_utils.rs @@ -0,0 +1,24 @@ +use ra_syntax::{SourceFile, TextUnit}; + +use crate::LocalEdit; +pub use test_utils::*; + +pub fn check_action Option>( + before: &str, + after: &str, + f: F, +) { + let (before_cursor_pos, before) = extract_offset(before); + let file = SourceFile::parse(&before); + let result = f(&file, before_cursor_pos).expect("code action is not applicable"); + let actual = result.edit.apply(&before); + let actual_cursor_pos = match result.cursor_position { + None => result + .edit + .apply_to_offset(before_cursor_pos) + .expect("cursor position is affected by the edit"), + Some(off) => off, + }; + let actual = add_cursor(&actual, actual_cursor_pos); + assert_eq_text!(after, &actual); +} -- cgit v1.2.3 From 01bca7114c0567961c875a1df5a60748cd872073 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Fri, 22 Mar 2019 17:10:20 +0100 Subject: Simplify changes and fix tests --- crates/ra_ide_api/src/test_utils.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide_api/src/test_utils.rs') diff --git a/crates/ra_ide_api/src/test_utils.rs b/crates/ra_ide_api/src/test_utils.rs index bfac0fce3..d0bd3a1e4 100644 --- a/crates/ra_ide_api/src/test_utils.rs +++ b/crates/ra_ide_api/src/test_utils.rs @@ -1,9 +1,9 @@ use ra_syntax::{SourceFile, TextUnit}; +use ra_text_edit::TextEdit; -use crate::LocalEdit; pub use test_utils::*; -pub fn check_action Option>( +pub fn check_action Option>( before: &str, after: &str, f: F, @@ -11,14 +11,9 @@ pub fn check_action Option>( let (before_cursor_pos, before) = extract_offset(before); let file = SourceFile::parse(&before); let result = f(&file, before_cursor_pos).expect("code action is not applicable"); - let actual = result.edit.apply(&before); - let actual_cursor_pos = match result.cursor_position { - None => result - .edit - .apply_to_offset(before_cursor_pos) - .expect("cursor position is affected by the edit"), - Some(off) => off, - }; + let actual = result.apply(&before); + let actual_cursor_pos = + result.apply_to_offset(before_cursor_pos).expect("cursor position is affected by the edit"); let actual = add_cursor(&actual, actual_cursor_pos); assert_eq_text!(after, &actual); } -- cgit v1.2.3