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.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index e4aa894ac..4c89ed87b 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -180,7 +180,7 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
180 let mut prev_line_start: Option<TextSize> = None; 180 let mut prev_line_start: Option<TextSize> = None;
181 let mut line_start: TextSize = 0.into(); 181 let mut line_start: TextSize = 0.into();
182 for line in lines_with_ends(text) { 182 for line in lines_with_ends(text) {
183 if let Some(idx) = line.find("//^") { 183 if let Some(idx) = line.find("//") {
184 let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]); 184 let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]);
185 for (line_range, text) in extract_line_annotations(&line[idx + "//".len()..]) { 185 for (line_range, text) in extract_line_annotations(&line[idx + "//".len()..]) {
186 res.push((line_range + offset, text)) 186 res.push((line_range + offset, text))
@@ -195,7 +195,15 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
195fn extract_line_annotations(mut line: &str) -> Vec<(TextRange, String)> { 195fn extract_line_annotations(mut line: &str) -> Vec<(TextRange, String)> {
196 let mut res = Vec::new(); 196 let mut res = Vec::new();
197 let mut offset: TextSize = 0.into(); 197 let mut offset: TextSize = 0.into();
198 while !line.is_empty() { 198 loop {
199 match line.find('^') {
200 Some(idx) => {
201 offset += TextSize::try_from(idx).unwrap();
202 line = &line[idx..];
203 }
204 None => break,
205 };
206
199 let len = line.chars().take_while(|&it| it == '^').count(); 207 let len = line.chars().take_while(|&it| it == '^').count();
200 assert!(len > 0); 208 assert!(len > 0);
201 let range = TextRange::at(offset, len.try_into().unwrap()); 209 let range = TextRange::at(offset, len.try_into().unwrap());