From bbc4dc995612916a4c0a99396b5259a5fb1dda80 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 29 Jun 2020 17:22:47 +0200 Subject: Update the rest of the tests --- crates/test_utils/src/lib.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'crates/test_utils') diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index e74f3b263..caf847273 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -161,7 +161,7 @@ pub fn add_cursor(text: &str, offset: TextSize) -> String { } /// Extracts `//^ some text` annotations -pub fn extract_annotations(text: &str) -> Vec<(TextSize, String)> { +pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> { let mut res = Vec::new(); let mut prev_line_start: Option = None; let mut line_start: TextSize = 0.into(); @@ -169,7 +169,7 @@ pub fn extract_annotations(text: &str) -> Vec<(TextSize, String)> { if let Some(idx) = line.find("//^") { let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]); let data = line[idx + "//^".len()..].trim().to_string(); - res.push((offset, data)) + res.push((TextRange::at(offset, 1.into()), data)) } prev_line_start = Some(line_start); line_start += TextSize::of(line); @@ -179,18 +179,20 @@ pub fn extract_annotations(text: &str) -> Vec<(TextSize, String)> { #[test] fn test_extract_annotations() { - let res = extract_annotations(&trim_indent( + let text = stdx::trim_indent( r#" fn main() { let x = 92; //^ def - - x + 1 + z + 1 } //^ i32 "#, - )); - - assert_eq!(res, vec![(20.into(), "def".into()), (47.into(), "i32".into())]); + ); + let res = extract_annotations(&text) + .into_iter() + .map(|(range, ann)| (&text[range], ann)) + .collect::>(); + assert_eq!(res, vec![("x", "def".into()), ("z", "i32".into()),]); } // Comparison functionality borrowed from cargo: -- cgit v1.2.3