aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/src/lib.rs18
1 files changed, 10 insertions, 8 deletions
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 {
161} 161}
162 162
163/// Extracts `//^ some text` annotations 163/// Extracts `//^ some text` annotations
164pub fn extract_annotations(text: &str) -> Vec<(TextSize, String)> { 164pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
165 let mut res = Vec::new(); 165 let mut res = Vec::new();
166 let mut prev_line_start: Option<TextSize> = None; 166 let mut prev_line_start: Option<TextSize> = None;
167 let mut line_start: TextSize = 0.into(); 167 let mut line_start: TextSize = 0.into();
@@ -169,7 +169,7 @@ pub fn extract_annotations(text: &str) -> Vec<(TextSize, String)> {
169 if let Some(idx) = line.find("//^") { 169 if let Some(idx) = line.find("//^") {
170 let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]); 170 let offset = prev_line_start.unwrap() + TextSize::of(&line[..idx + "//".len()]);
171 let data = line[idx + "//^".len()..].trim().to_string(); 171 let data = line[idx + "//^".len()..].trim().to_string();
172 res.push((offset, data)) 172 res.push((TextRange::at(offset, 1.into()), data))
173 } 173 }
174 prev_line_start = Some(line_start); 174 prev_line_start = Some(line_start);
175 line_start += TextSize::of(line); 175 line_start += TextSize::of(line);
@@ -179,18 +179,20 @@ pub fn extract_annotations(text: &str) -> Vec<(TextSize, String)> {
179 179
180#[test] 180#[test]
181fn test_extract_annotations() { 181fn test_extract_annotations() {
182 let res = extract_annotations(&trim_indent( 182 let text = stdx::trim_indent(
183 r#" 183 r#"
184fn main() { 184fn main() {
185 let x = 92; 185 let x = 92;
186 //^ def 186 //^ def
187 187 z + 1
188 x + 1
189} //^ i32 188} //^ i32
190 "#, 189 "#,
191 )); 190 );
192 191 let res = extract_annotations(&text)
193 assert_eq!(res, vec![(20.into(), "def".into()), (47.into(), "i32".into())]); 192 .into_iter()
193 .map(|(range, ann)| (&text[range], ann))
194 .collect::<Vec<_>>();
195 assert_eq!(res, vec![("x", "def".into()), ("z", "i32".into()),]);
194} 196}
195 197
196// Comparison functionality borrowed from cargo: 198// Comparison functionality borrowed from cargo: