aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api_light/src/test_utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api_light/src/test_utils.rs')
-rw-r--r--crates/ra_ide_api_light/src/test_utils.rs31
1 files changed, 1 insertions, 30 deletions
diff --git a/crates/ra_ide_api_light/src/test_utils.rs b/crates/ra_ide_api_light/src/test_utils.rs
index 22ded2435..bfac0fce3 100644
--- a/crates/ra_ide_api_light/src/test_utils.rs
+++ b/crates/ra_ide_api_light/src/test_utils.rs
@@ -1,4 +1,4 @@
1use ra_syntax::{SourceFile, TextRange, TextUnit}; 1use ra_syntax::{SourceFile, TextUnit};
2 2
3use crate::LocalEdit; 3use crate::LocalEdit;
4pub use test_utils::*; 4pub use test_utils::*;
@@ -22,32 +22,3 @@ pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>(
22 let actual = add_cursor(&actual, actual_cursor_pos); 22 let actual = add_cursor(&actual, actual_cursor_pos);
23 assert_eq_text!(after, &actual); 23 assert_eq_text!(after, &actual);
24} 24}
25
26pub fn check_action_not_applicable<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>(
27 text: &str,
28 f: F,
29) {
30 let (text_cursor_pos, text) = extract_offset(text);
31 let file = SourceFile::parse(&text);
32 assert!(
33 f(&file, text_cursor_pos).is_none(),
34 "code action is applicable but it shouldn't"
35 );
36}
37
38pub fn check_action_range<F: Fn(&SourceFile, TextRange) -> Option<LocalEdit>>(
39 before: &str,
40 after: &str,
41 f: F,
42) {
43 let (range, before) = extract_range(before);
44 let file = SourceFile::parse(&before);
45 let result = f(&file, range).expect("code action is not applicable");
46 let actual = result.edit.apply(&before);
47 let actual_cursor_pos = match result.cursor_position {
48 None => result.edit.apply_to_offset(range.start()).unwrap(),
49 Some(off) => off,
50 };
51 let actual = add_cursor(&actual, actual_cursor_pos);
52 assert_eq_text!(after, &actual);
53}