aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/test_utils.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-28 12:47:12 +0100
committerAleksey Kladov <[email protected]>2018-08-28 12:47:12 +0100
commit748a4cacd24d9ecdca995e66117a10a1562e7d5d (patch)
tree4640f14c4c4417743815f9792058df30feac70dd /crates/libeditor/src/test_utils.rs
parent6c41a205a908eb94f139f968f803e728fc3418c6 (diff)
Reorganize tests
Diffstat (limited to 'crates/libeditor/src/test_utils.rs')
-rw-r--r--crates/libeditor/src/test_utils.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/libeditor/src/test_utils.rs b/crates/libeditor/src/test_utils.rs
new file mode 100644
index 000000000..475f560fa
--- /dev/null
+++ b/crates/libeditor/src/test_utils.rs
@@ -0,0 +1,20 @@
1use libsyntax2::{File, TextUnit};
2pub use _test_utils::*;
3use ActionResult;
4
5pub fn check_action<F: Fn(&File, TextUnit) -> Option<ActionResult>> (
6 before: &str,
7 after: &str,
8 f: F,
9) {
10 let (before_cursor_pos, before) = extract_offset(before);
11 let file = File::parse(&before);
12 let result = f(&file, before_cursor_pos).expect("code action is not applicable");
13 let actual = result.edit.apply(&before);
14 let actual_cursor_pos = match result.cursor_position {
15 None => result.edit.apply_to_offset(before_cursor_pos).unwrap(),
16 Some(off) => off,
17 };
18 let actual = add_cursor(&actual, actual_cursor_pos);
19 assert_eq_text!(after, &actual);
20}