aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils/src')
-rw-r--r--crates/test_utils/src/lib.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index caf847273..f9d6c6c96 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -11,6 +11,7 @@ pub mod mark;
11mod fixture; 11mod fixture;
12 12
13use std::{ 13use std::{
14 convert::TryInto,
14 env, fs, 15 env, fs,
15 path::{Path, PathBuf}, 16 path::{Path, PathBuf},
16}; 17};
@@ -168,8 +169,10 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
168 for line in lines_with_ends(text) { 169 for line in lines_with_ends(text) {
169 if let Some(idx) = line.find("//^") { 170 if let Some(idx) = line.find("//^") {
170 let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]); 171 let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]);
171 let data = line[idx + "//^".len()..].trim().to_string(); 172 let marker_and_data = &line[idx + "//".len()..];
172 res.push((TextRange::at(offset, 1.into()), data)) 173 let len = marker_and_data.chars().take_while(|&it| it == '^').count();
174 let data = marker_and_data[len..].trim().to_string();
175 res.push((TextRange::at(offset, len.try_into().unwrap()), data))
173 } 176 }
174 prev_line_start = Some(line_start); 177 prev_line_start = Some(line_start);
175 line_start += TextSize::of(line); 178 line_start += TextSize::of(line);
@@ -184,15 +187,15 @@ fn test_extract_annotations() {
184fn main() { 187fn main() {
185 let x = 92; 188 let x = 92;
186 //^ def 189 //^ def
187 z + 1 190 zoo + 1
188} //^ i32 191} //^^^ i32
189 "#, 192 "#,
190 ); 193 );
191 let res = extract_annotations(&text) 194 let res = extract_annotations(&text)
192 .into_iter() 195 .into_iter()
193 .map(|(range, ann)| (&text[range], ann)) 196 .map(|(range, ann)| (&text[range], ann))
194 .collect::<Vec<_>>(); 197 .collect::<Vec<_>>();
195 assert_eq!(res, vec![("x", "def".into()), ("z", "i32".into()),]); 198 assert_eq!(res, vec![("x", "def".into()), ("zoo", "i32".into()),]);
196} 199}
197 200
198// Comparison functionality borrowed from cargo: 201// Comparison functionality borrowed from cargo: