1
- use regex:: Regex ;
2
1
use serde:: Deserialize ;
3
2
use std:: fmt:: { self , Display , Formatter } ;
4
3
use std:: fs:: { self , remove_file, File } ;
5
4
use std:: io:: { self , BufRead , BufReader } ;
6
5
use std:: path:: PathBuf ;
7
6
use std:: process:: { self , Command } ;
8
7
use std:: { array, env, mem} ;
8
+ use winnow:: ascii:: { space0, space1} ;
9
+ use winnow:: combinator:: opt;
10
+ use winnow:: Parser ;
9
11
10
12
const RUSTC_COLOR_ARGS : & [ & str ] = & [ "--color" , "always" ] ;
11
13
const RUSTC_EDITION_ARGS : & [ & str ] = & [ "--edition" , "2021" ] ;
12
14
const 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" ;
14
15
const CONTEXT : usize = 2 ;
15
16
const CLIPPY_CARGO_TOML_PATH : & str = "./exercises/22_clippy/Cargo.toml" ;
16
17
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
+
17
36
// Get a temporary file name that is hopefully unique
18
37
#[ inline]
19
38
fn temp_file ( ) -> String {
@@ -223,7 +242,6 @@ path = "{}.rs""#,
223
242
Ok ( n)
224
243
} ;
225
244
226
- let re = Regex :: new ( I_AM_DONE_REGEX ) . unwrap ( ) ;
227
245
let mut matched_line_ind: usize = 0 ;
228
246
let mut prev_lines: [ _ ; CONTEXT ] = array:: from_fn ( |_| String :: with_capacity ( 256 ) ) ;
229
247
let mut line = String :: with_capacity ( 256 ) ;
@@ -232,7 +250,7 @@ path = "{}.rs""#,
232
250
match read_line ( & mut line) {
233
251
Ok ( 0 ) => break ,
234
252
Ok ( _) => {
235
- if re . is_match ( & line) {
253
+ if not_done ( & line) {
236
254
let mut context = Vec :: with_capacity ( 2 * CONTEXT + 1 ) ;
237
255
for ( ind, prev_line) in prev_lines
238
256
. into_iter ( )
@@ -413,4 +431,22 @@ mod test {
413
431
let out = exercise. compile ( ) . unwrap ( ) . run ( ) . unwrap ( ) ;
414
432
assert ! ( out. stdout. contains( "THIS TEST TOO SHALL PASS" ) ) ;
415
433
}
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
+ }
416
452
}
0 commit comments