diff options
Diffstat (limited to 'crates/ra_ide_api/src/test_utils.rs')
-rw-r--r-- | crates/ra_ide_api/src/test_utils.rs | 19 |
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 @@ | |||
1 | use ra_syntax::{SourceFile, TextUnit}; | ||
2 | use ra_text_edit::TextEdit; | ||
3 | |||
4 | pub use test_utils::*; | ||
5 | |||
6 | pub 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 | } | ||