File tree Expand file tree Collapse file tree 1 file changed +19
-20
lines changed Expand file tree Collapse file tree 1 file changed +19
-20
lines changed Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
176
176
. next ( )
177
177
. expect ( "empty fixture" ) ;
178
178
179
- let lines = fixture
179
+ let mut lines = fixture
180
180
. split ( '\n' ) // don't use `.lines` to not drop `\r\n`
181
181
. filter_map ( |line| {
182
182
if line. len ( ) >= margin {
@@ -189,29 +189,28 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
189
189
} ) ;
190
190
191
191
let mut res = Vec :: new ( ) ;
192
- let mut buf = String :: new ( ) ;
193
- let mut meta : Option < & str > = None ;
194
-
195
- macro_rules! flush {
196
- ( ) => {
197
- if let Some ( meta ) = meta {
198
- res . push ( FixtureEntry { meta : meta . to_string ( ) , text : buf . clone ( ) } ) ;
199
- buf . clear ( ) ;
192
+ let mut meta = None ;
193
+ loop {
194
+ let mut next_meta = None ;
195
+ let mut text = String :: new ( ) ;
196
+ for line in lines . by_ref ( ) {
197
+ if line . starts_with ( "//-" ) {
198
+ next_meta = Some ( line [ "//-" . len ( ) .. ] . trim ( ) . to_string ( ) ) ;
199
+ break ;
200
200
}
201
- } ;
202
- } ;
201
+ text. push_str ( line) ;
202
+ text. push ( '\n' ) ;
203
+ }
203
204
204
- for line in lines {
205
- if line . starts_with ( "//-" ) {
206
- flush ! ( ) ;
207
- buf . clear ( ) ;
208
- meta = Some ( line [ "//-" . len ( ) .. ] . trim ( ) ) ;
209
- continue ;
205
+ if let Some ( meta ) = meta {
206
+ res . push ( FixtureEntry { meta , text } ) ;
207
+ }
208
+ meta = next_meta ;
209
+ if meta. is_none ( ) {
210
+ break ;
210
211
}
211
- buf. push_str ( line) ;
212
- buf. push ( '\n' ) ;
213
212
}
214
- flush ! ( ) ;
213
+
215
214
res
216
215
}
217
216
You can’t perform that action at this time.
0 commit comments