aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-31 18:37:32 +0000
committerAleksey Kladov <[email protected]>2018-10-31 18:37:40 +0000
commit64ce895ef0beea75e9ecfcdf5b4e226a8a6336d8 (patch)
treeaf07f03610a2ef1f8a49d773170146d0c1774750 /crates/test_utils
parentb58ca6b1a68471f6944893b94f09cd56dc28f837 (diff)
extract fixture parsing
Diffstat (limited to 'crates/test_utils')
-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}