diff options
author | Aleksey Kladov <[email protected]> | 2020-07-14 13:01:54 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-14 13:01:54 +0100 |
commit | 0b0865ab226d57c88e22b6b395d033f68f2c11af (patch) | |
tree | cd0b31593a7b2b38f408a9f044ac89a02d3bee1a /crates/test_utils/src | |
parent | 83271f9b9977267492a59c4264fbd7dff9f7ea02 (diff) |
Generaize annotation extraction
Diffstat (limited to 'crates/test_utils/src')
-rw-r--r-- | crates/test_utils/src/lib.rs | 12 |
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)> { | |||
195 | fn extract_line_annotations(mut line: &str) -> Vec<(TextRange, String)> { | 195 | fn 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()); |