@@ -4,9 +4,8 @@ use rustell::*;
44
55#[ test]
66fn test_parser ( ) {
7- let src = "use std::io::Read;" ;
8- let slp = sloppy ( src) ;
9- let ast = vec ! [ Expr :: Use ( ExprUse :: Item {
7+ let lhs = "use std::io::Read;" ;
8+ let rhs = vec ! [ Expr :: Use ( ExprUse :: Item {
109 module: "std" ,
1110 rename: None ,
1211 nested: Some ( Box :: new( ExprUse :: Item {
@@ -19,9 +18,9 @@ fn test_parser() {
1918 } ) ) ,
2019 } ) ) ,
2120 } ) ] ;
22- assert_eq ! ( parse ( src ) , ast ) ;
23- assert_eq ! ( parse ( & slp ) , ast ) ;
24- assert_eq ! ( parse ( & encode( ast . clone ( ) ) ) , ast )
21+ assert_eq ! ( decode ( lhs ) , rhs ) ;
22+ assert_eq ! ( decode ( & sloppy ( lhs ) ) , rhs ) ;
23+ assert_eq ! ( decode ( & encode( & rhs ) ) , rhs )
2524}
2625
2726#[ test]
@@ -51,8 +50,9 @@ fn test_parser_many() {
5150 } ,
5251 ] ) ) ) ,
5352 } ) ] ;
54- assert_eq ! ( parse( lhs) , rhs) ;
55- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
53+ assert_eq ! ( decode( lhs) , rhs) ;
54+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
55+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
5656}
5757
5858#[ test]
@@ -67,8 +67,9 @@ fn test_parser_glob() {
6767 nested: Some ( Box :: new( ExprUse :: Glob ) ) ,
6868 } ) ) ,
6969 } ) ] ;
70- assert_eq ! ( parse( lhs) , rhs) ;
71- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
70+ assert_eq ! ( decode( lhs) , rhs) ;
71+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
72+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
7273}
7374
7475#[ test]
@@ -87,8 +88,9 @@ fn test_parser_rename() {
8788 } ) ) ,
8889 } ) ) ,
8990 } ) ] ;
90- assert_eq ! ( parse( lhs) , rhs) ;
91- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
91+ assert_eq ! ( decode( lhs) , rhs) ;
92+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
93+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
9294}
9395
9496#[ test]
@@ -114,8 +116,9 @@ fn test_parser_complex() {
114116 } ,
115117 ] ) ) ) ,
116118 } ) ] ;
117- assert_eq ! ( parse( lhs) , rhs) ;
118- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
119+ assert_eq ! ( decode( lhs) , rhs) ;
120+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
121+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
119122}
120123
121124#[ test]
@@ -134,8 +137,9 @@ fn test_parser_crate() {
134137 } ) ) ,
135138 } ) ) ,
136139 } ) ] ;
137- assert_eq ! ( parse( lhs) , rhs) ;
138- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
140+ assert_eq ! ( decode( lhs) , rhs) ;
141+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
142+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
139143}
140144
141145#[ test]
@@ -167,8 +171,9 @@ fn test_parser_other_then_use() {
167171 } ) ) ,
168172 } ) ,
169173 ] ;
170- assert_eq ! ( parse( lhs) , rhs) ;
171- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
174+ assert_eq ! ( decode( lhs) , rhs) ;
175+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
176+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
172177}
173178
174179#[ test]
@@ -200,8 +205,9 @@ fn test_parser_multiple() {
200205 } ) ,
201206 Expr :: Other ( "\n " ) ,
202207 ] ;
203- assert_eq ! ( parse( lhs) , rhs) ;
204- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
208+ assert_eq ! ( decode( lhs) , rhs) ;
209+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
210+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
205211}
206212
207213#[ test]
@@ -242,8 +248,9 @@ fn test_parser_multiple_with_other() {
242248 } ) ,
243249 Expr :: Other ( "\n " ) ,
244250 ] ;
245- assert_eq ! ( parse( lhs) , rhs) ;
246- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
251+ assert_eq ! ( decode( lhs) , rhs) ;
252+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
253+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
247254}
248255
249256#[ test]
@@ -313,18 +320,19 @@ fn test_parser_mixed_all_cases() {
313320 "# ,
314321 ) ,
315322 ] ;
316- assert_eq ! ( parse( lhs) , rhs) ;
317- assert_eq ! ( parse( & sloppy( lhs) ) , rhs)
323+ assert_eq ! ( decode( lhs) , rhs) ;
324+ assert_eq ! ( decode( & sloppy( lhs) ) , rhs) ;
325+ assert_eq ! ( decode( & encode( & rhs) ) , rhs)
318326}
319327
320328fn sloppy ( src : & str ) -> String {
321329 src. replace ( ";" , "" )
322330}
323331
324- fn parse ( src : & str ) -> Vec < Expr > {
332+ fn decode ( src : & str ) -> Vec < Expr > {
325333 decode:: expr ( ) . parse ( src) . into_result ( ) . unwrap ( )
326334}
327335
328- fn encode ( ast : Vec < Expr > ) -> String {
336+ fn encode ( ast : & [ Expr ] ) -> String {
329337 encode:: expr ( ast) . collect ( )
330338}
0 commit comments