1- use regex:: Regex ;
21use serde:: Deserialize ;
32use std:: fmt:: { self , Display , Formatter } ;
43use std:: fs:: { self , remove_file, File } ;
54use std:: io:: { self , BufRead , BufReader } ;
65use std:: path:: PathBuf ;
76use std:: process:: { self , Command } ;
87use std:: { array, env, mem} ;
8+ use winnow:: ascii:: { space0, space1} ;
9+ use winnow:: combinator:: opt;
10+ use winnow:: Parser ;
911
1012const RUSTC_COLOR_ARGS : & [ & str ] = & [ "--color" , "always" ] ;
1113const RUSTC_EDITION_ARGS : & [ & str ] = & [ "--edition" , "2021" ] ;
1214const RUSTC_NO_DEBUG_ARGS : & [ & str ] = & [ "-C" , "strip=debuginfo" ] ;
13- const I_AM_DONE_REGEX : & str = r"^\s*///?\s*I\s+AM\s+NOT\s+DONE" ;
1415const CONTEXT : usize = 2 ;
1516const CLIPPY_CARGO_TOML_PATH : & str = "./exercises/22_clippy/Cargo.toml" ;
1617
18+ fn not_done ( input : & str ) -> bool {
19+ (
20+ space0 :: < _ , ( ) > ,
21+ "//" ,
22+ opt ( '/' ) ,
23+ space0,
24+ 'I' ,
25+ space1,
26+ "AM" ,
27+ space1,
28+ "NOT" ,
29+ space1,
30+ "DONE" ,
31+ )
32+ . parse_next ( & mut & * input)
33+ . is_ok ( )
34+ }
35+
1736// Get a temporary file name that is hopefully unique
1837#[ inline]
1938fn temp_file ( ) -> String {
@@ -223,7 +242,6 @@ path = "{}.rs""#,
223242 Ok ( n)
224243 } ;
225244
226- let re = Regex :: new ( I_AM_DONE_REGEX ) . unwrap ( ) ;
227245 let mut matched_line_ind: usize = 0 ;
228246 let mut prev_lines: [ _ ; CONTEXT ] = array:: from_fn ( |_| String :: with_capacity ( 256 ) ) ;
229247 let mut line = String :: with_capacity ( 256 ) ;
@@ -232,7 +250,7 @@ path = "{}.rs""#,
232250 match read_line ( & mut line) {
233251 Ok ( 0 ) => break ,
234252 Ok ( _) => {
235- if re . is_match ( & line) {
253+ if not_done ( & line) {
236254 let mut context = Vec :: with_capacity ( 2 * CONTEXT + 1 ) ;
237255 for ( ind, prev_line) in prev_lines
238256 . into_iter ( )
@@ -413,4 +431,22 @@ mod test {
413431 let out = exercise. compile ( ) . unwrap ( ) . run ( ) . unwrap ( ) ;
414432 assert ! ( out. stdout. contains( "THIS TEST TOO SHALL PASS" ) ) ;
415433 }
434+
435+ #[ test]
436+ fn test_not_done ( ) {
437+ assert ! ( not_done( "// I AM NOT DONE" ) ) ;
438+ assert ! ( not_done( "/// I AM NOT DONE" ) ) ;
439+ assert ! ( not_done( "// I AM NOT DONE" ) ) ;
440+ assert ! ( not_done( "/// I AM NOT DONE" ) ) ;
441+ assert ! ( not_done( "// I AM NOT DONE" ) ) ;
442+ assert ! ( not_done( "// I AM NOT DONE" ) ) ;
443+ assert ! ( not_done( "// I AM NOT DONE" ) ) ;
444+ assert ! ( not_done( "// I AM NOT DONE " ) ) ;
445+ assert ! ( not_done( "// I AM NOT DONE!" ) ) ;
446+
447+ assert ! ( !not_done( "I AM NOT DONE" ) ) ;
448+ assert ! ( !not_done( "// NOT DONE" ) ) ;
449+ assert ! ( !not_done( "DONE" ) ) ;
450+ assert ! ( !not_done( "// i am not done" ) ) ;
451+ }
416452}
0 commit comments