File tree Expand file tree Collapse file tree 2 files changed +42
-17
lines changed Expand file tree Collapse file tree 2 files changed +42
-17
lines changed Original file line number Diff line number Diff line change @@ -89,18 +89,6 @@ fn expr_raw<'a>() -> impl Decode<'a, Expr<'a>> {
8989 . map ( Expr :: Raw )
9090}
9191
92- fn token < ' a > (
93- tok : impl Decode < ' a , & ' a str > + Clone ,
94- ) -> impl Decode < ' a , & ' a str > + Clone {
95- whitespace ( ) . or_not ( ) . ignore_then ( tok)
96- }
97-
98- fn lexeme < ' a > (
99- seq : & ' a str ,
100- ) -> impl Decode < ' a , & ' a str > + Clone {
101- token ( just ( seq) )
102- }
103-
10492fn keyword < ' a > ( ) -> impl Decode < ' a , & ' a str > + Clone {
10593 keyword_except ( & [ ] )
10694}
@@ -130,3 +118,15 @@ fn keyword_except<'a>(
130118 . collect :: < Vec < _ > > ( ) ,
131119 )
132120}
121+
122+ fn token < ' a > (
123+ tok : impl Decode < ' a , & ' a str > + Clone ,
124+ ) -> impl Decode < ' a , & ' a str > + Clone {
125+ whitespace ( ) . or_not ( ) . ignore_then ( tok)
126+ }
127+
128+ fn lexeme < ' a > (
129+ seq : & ' a str ,
130+ ) -> impl Decode < ' a , & ' a str > + Clone {
131+ token ( just ( seq) )
132+ }
Original file line number Diff line number Diff line change @@ -326,11 +326,36 @@ fn test_parser_mixed_all_cases() {
326326}
327327
328328#[ test]
329- fn test_rountrip_lib ( ) {
330- let src =
331- std:: fs:: read_to_string ( "./src/lib.rs" ) . unwrap ( ) ;
332- let ast = decode ( & src) ;
333- assert_eq ! ( decode( & encode( & ast) ) , ast) ;
329+ fn test_roundtrip_own_sources ( ) {
330+ get_rust_files ( "./" ) . into_iter ( ) . for_each ( |path| {
331+ let lhs = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
332+ let rhs = decode ( & lhs) ;
333+ assert_eq ! (
334+ decode( & encode( & rhs) ) ,
335+ rhs,
336+ "Roundtrip failed for the file: {}" ,
337+ path
338+ ) ;
339+ } ) ;
340+ }
341+
342+ fn get_rust_files ( dir : & str ) -> Vec < String > {
343+ std:: fs:: read_dir ( dir)
344+ . unwrap ( )
345+ . flat_map ( |item| {
346+ let path = item. unwrap ( ) . path ( ) ;
347+ let name = path. to_str ( ) . unwrap ( ) ;
348+ if path. is_dir ( ) {
349+ get_rust_files ( name)
350+ } else if path. is_file ( )
351+ && name. ends_with ( ".rs" )
352+ {
353+ vec ! [ name. to_string( ) ]
354+ } else {
355+ vec ! [ ]
356+ }
357+ } )
358+ . collect ( )
334359}
335360
336361fn sloppy ( src : & str ) -> String {
You can’t perform that action at this time.
0 commit comments