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.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index dbe2997eb..562dbcbb3 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -87,3 +87,45 @@ pub fn add_cursor(text: &str, offset: TextUnit) -> String {
87 res.push_str(&text[offset..]); 87 res.push_str(&text[offset..]);
88 res 88 res
89} 89}
90
91
92#[derive(Debug)]
93pub struct FixtureEntry {
94 pub meta: String,
95 pub text: String,
96}
97
98/// Parses text wich looks like this:
99///
100/// ```notrust
101/// //- some meta
102/// line 1
103/// line 2
104/// // - other meta
105/// ```
106pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
107 let mut res = Vec::new();
108 let mut buf = String::new();
109 let mut meta: Option<&str> = None;
110
111 macro_rules! flush {
112 () => {
113 if let Some(meta) = meta {
114 res.push(FixtureEntry { meta: meta.to_string(), text: buf.clone() });
115 buf.clear();
116 }
117 };
118 };
119 for line in fixture.lines() {
120 if line.starts_with("//-") {
121 flush!();
122 buf.clear();
123 meta = Some(line["//-".len()..].trim());
124 continue;
125 }
126 buf.push_str(line);
127 buf.push('\n');
128 }
129 flush!();
130 res
131}