diff options
author | Aleksey Kladov <[email protected]> | 2018-09-16 10:54:24 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-16 11:07:39 +0100 |
commit | b5021411a84822cb3f1e3aeffad9550dd15bdeb6 (patch) | |
tree | 9dca564f8e51b298dced01c4ce669c756dce3142 /crates/ra_editor/src/test_utils.rs | |
parent | ba0bfeee12e19da40b5eabc8d0408639af10e96f (diff) |
rename all things
Diffstat (limited to 'crates/ra_editor/src/test_utils.rs')
-rw-r--r-- | crates/ra_editor/src/test_utils.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/ra_editor/src/test_utils.rs b/crates/ra_editor/src/test_utils.rs new file mode 100644 index 000000000..c4ea4db6c --- /dev/null +++ b/crates/ra_editor/src/test_utils.rs | |||
@@ -0,0 +1,37 @@ | |||
1 | use ra_syntax::{File, TextUnit, TextRange}; | ||
2 | pub use _test_utils::*; | ||
3 | use LocalEdit; | ||
4 | |||
5 | pub fn check_action<F: Fn(&File, TextUnit) -> Option<LocalEdit>> ( | ||
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 | } | ||
21 | |||
22 | pub fn check_action_range<F: Fn(&File, TextRange) -> Option<LocalEdit>> ( | ||
23 | before: &str, | ||
24 | after: &str, | ||
25 | f: F, | ||
26 | ) { | ||
27 | let (range, before) = extract_range(before); | ||
28 | let file = File::parse(&before); | ||
29 | let result = f(&file, range).expect("code action is not applicable"); | ||
30 | let actual = result.edit.apply(&before); | ||
31 | let actual_cursor_pos = match result.cursor_position { | ||
32 | None => result.edit.apply_to_offset(range.start()).unwrap(), | ||
33 | Some(off) => off, | ||
34 | }; | ||
35 | let actual = add_cursor(&actual, actual_cursor_pos); | ||
36 | assert_eq_text!(after, &actual); | ||
37 | } | ||