diff options
Diffstat (limited to 'crates/test_utils')
-rw-r--r-- | crates/test_utils/src/lib.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 562dbcbb3..8980f077f 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -8,6 +8,8 @@ use text_unit::{TextRange, TextUnit}; | |||
8 | 8 | ||
9 | pub use self::difference::Changeset as __Changeset; | 9 | pub use self::difference::Changeset as __Changeset; |
10 | 10 | ||
11 | pub const CURSOR_MARKER: &str = "<|>"; | ||
12 | |||
11 | #[macro_export] | 13 | #[macro_export] |
12 | macro_rules! assert_eq_text { | 14 | macro_rules! assert_eq_text { |
13 | ($expected:expr, $actual:expr) => {{ | 15 | ($expected:expr, $actual:expr) => {{ |
@@ -45,11 +47,10 @@ pub fn extract_offset(text: &str) -> (TextUnit, String) { | |||
45 | } | 47 | } |
46 | 48 | ||
47 | pub fn try_extract_offset(text: &str) -> Option<(TextUnit, String)> { | 49 | pub fn try_extract_offset(text: &str) -> Option<(TextUnit, String)> { |
48 | let cursor = "<|>"; | 50 | let cursor_pos = text.find(CURSOR_MARKER)?; |
49 | let cursor_pos = text.find(cursor)?; | 51 | let mut new_text = String::with_capacity(text.len() - CURSOR_MARKER.len()); |
50 | let mut new_text = String::with_capacity(text.len() - cursor.len()); | ||
51 | new_text.push_str(&text[..cursor_pos]); | 52 | new_text.push_str(&text[..cursor_pos]); |
52 | new_text.push_str(&text[cursor_pos + cursor.len()..]); | 53 | new_text.push_str(&text[cursor_pos + CURSOR_MARKER.len()..]); |
53 | let cursor_pos = TextUnit::from(cursor_pos as u32); | 54 | let cursor_pos = TextUnit::from(cursor_pos as u32); |
54 | Some((cursor_pos, new_text)) | 55 | Some((cursor_pos, new_text)) |
55 | } | 56 | } |
@@ -116,7 +117,22 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> { | |||
116 | } | 117 | } |
117 | }; | 118 | }; |
118 | }; | 119 | }; |
119 | for line in fixture.lines() { | 120 | let margin = fixture.lines() |
121 | .filter(|it| it.trim_start().starts_with("//-")) | ||
122 | .map(|it| it.len() - it.trim_start().len()) | ||
123 | .next().expect("empty fixture"); | ||
124 | let lines = fixture.lines() | ||
125 | .filter_map(|line| { | ||
126 | if line.len() >= margin { | ||
127 | assert!(line[..margin].trim().is_empty()); | ||
128 | Some(&line[margin..]) | ||
129 | } else { | ||
130 | assert!(line.trim().is_empty()); | ||
131 | None | ||
132 | } | ||
133 | }); | ||
134 | |||
135 | for line in lines { | ||
120 | if line.starts_with("//-") { | 136 | if line.starts_with("//-") { |
121 | flush!(); | 137 | flush!(); |
122 | buf.clear(); | 138 | buf.clear(); |