@@ -535,6 +535,29 @@ impl TestProps {
535
535
}
536
536
}
537
537
538
+ pub fn line_directive < ' line > (
539
+ comment : & str ,
540
+ ln : & ' line str ,
541
+ ) -> Option < ( Option < & ' line str > , & ' line str ) > {
542
+ if ln. starts_with ( comment) {
543
+ let ln = ln[ comment. len ( ) ..] . trim_start ( ) ;
544
+ if ln. starts_with ( '[' ) {
545
+ // A comment like `//[foo]` is specific to revision `foo`
546
+ if let Some ( close_brace) = ln. find ( ']' ) {
547
+ let lncfg = & ln[ 1 ..close_brace] ;
548
+
549
+ Some ( ( Some ( lncfg) , ln[ ( close_brace + 1 ) ..] . trim_start ( ) ) )
550
+ } else {
551
+ panic ! ( "malformed condition directive: expected `{}[foo]`, found `{}`" , comment, ln)
552
+ }
553
+ } else {
554
+ Some ( ( None , ln) )
555
+ }
556
+ } else {
557
+ None
558
+ }
559
+ }
560
+
538
561
fn iter_header < R : Read > ( testfile : & Path , rdr : R , it : & mut dyn FnMut ( Option < & str > , & str ) ) {
539
562
if testfile. is_dir ( ) {
540
563
return ;
@@ -557,17 +580,8 @@ fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>
557
580
let ln = ln. trim ( ) ;
558
581
if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
559
582
return ;
560
- } else if ln. starts_with ( comment) && ln[ comment. len ( ) ..] . trim_start ( ) . starts_with ( '[' ) {
561
- // A comment like `//[foo]` is specific to revision `foo`
562
- if let Some ( close_brace) = ln. find ( ']' ) {
563
- let open_brace = ln. find ( '[' ) . unwrap ( ) ;
564
- let lncfg = & ln[ open_brace + 1 ..close_brace] ;
565
- it ( Some ( lncfg) , ln[ ( close_brace + 1 ) ..] . trim_start ( ) ) ;
566
- } else {
567
- panic ! ( "malformed condition directive: expected `{}[foo]`, found `{}`" , comment, ln)
568
- }
569
- } else if ln. starts_with ( comment) {
570
- it ( None , ln[ comment. len ( ) ..] . trim_start ( ) ) ;
583
+ } else if let Some ( ( lncfg, ln) ) = line_directive ( comment, ln) {
584
+ it ( lncfg, ln) ;
571
585
}
572
586
}
573
587
}
0 commit comments