aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/test_utils.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-22 17:56:23 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-22 17:56:23 +0000
commit3604f23e98d01fe9d89e5cdcf76a51cb9c1d6768 (patch)
treede867640036faf167ff07a62d22db02c37f48088 /crates/ra_ide_api/src/test_utils.rs
parent6e324d38d6ef3e250ff32a397f4777699e006f7f (diff)
parent01bca7114c0567961c875a1df5a60748cd872073 (diff)
Merge #1012
1012: Move join_lines and test_utils to ra_ide_api r=matklad a=detrumi Part of #1009 Co-authored-by: Wilco Kusee <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/test_utils.rs')
-rw-r--r--crates/ra_ide_api/src/test_utils.rs19
1 files changed, 19 insertions, 0 deletions
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..d0bd3a1e4
--- /dev/null
+++ b/crates/ra_ide_api/src/test_utils.rs
@@ -0,0 +1,19 @@
1use ra_syntax::{SourceFile, TextUnit};
2use ra_text_edit::TextEdit;
3
4pub use test_utils::*;
5
6pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<TextEdit>>(
7 before: &str,
8 after: &str,
9 f: F,
10) {
11 let (before_cursor_pos, before) = extract_offset(before);
12 let file = SourceFile::parse(&before);
13 let result = f(&file, before_cursor_pos).expect("code action is not applicable");
14 let actual = result.apply(&before);
15 let actual_cursor_pos =
16 result.apply_to_offset(before_cursor_pos).expect("cursor position is affected by the edit");
17 let actual = add_cursor(&actual, actual_cursor_pos);
18 assert_eq_text!(after, &actual);
19}