@@ -4,9 +4,8 @@ use rustell::*;
4
4
5
5
#[ test]
6
6
fn 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 {
10
9
module: "std" ,
11
10
rename: None ,
12
11
nested: Some ( Box :: new( ExprUse :: Item {
@@ -19,9 +18,9 @@ fn test_parser() {
19
18
} ) ) ,
20
19
} ) ) ,
21
20
} ) ] ;
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 )
25
24
}
26
25
27
26
#[ test]
@@ -51,8 +50,9 @@ fn test_parser_many() {
51
50
} ,
52
51
] ) ) ) ,
53
52
} ) ] ;
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)
56
56
}
57
57
58
58
#[ test]
@@ -67,8 +67,9 @@ fn test_parser_glob() {
67
67
nested: Some ( Box :: new( ExprUse :: Glob ) ) ,
68
68
} ) ) ,
69
69
} ) ] ;
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)
72
73
}
73
74
74
75
#[ test]
@@ -87,8 +88,9 @@ fn test_parser_rename() {
87
88
} ) ) ,
88
89
} ) ) ,
89
90
} ) ] ;
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)
92
94
}
93
95
94
96
#[ test]
@@ -114,8 +116,9 @@ fn test_parser_complex() {
114
116
} ,
115
117
] ) ) ) ,
116
118
} ) ] ;
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)
119
122
}
120
123
121
124
#[ test]
@@ -134,8 +137,9 @@ fn test_parser_crate() {
134
137
} ) ) ,
135
138
} ) ) ,
136
139
} ) ] ;
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)
139
143
}
140
144
141
145
#[ test]
@@ -167,8 +171,9 @@ fn test_parser_other_then_use() {
167
171
} ) ) ,
168
172
} ) ,
169
173
] ;
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)
172
177
}
173
178
174
179
#[ test]
@@ -200,8 +205,9 @@ fn test_parser_multiple() {
200
205
} ) ,
201
206
Expr :: Other ( "\n " ) ,
202
207
] ;
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)
205
211
}
206
212
207
213
#[ test]
@@ -242,8 +248,9 @@ fn test_parser_multiple_with_other() {
242
248
} ) ,
243
249
Expr :: Other ( "\n " ) ,
244
250
] ;
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)
247
254
}
248
255
249
256
#[ test]
@@ -313,18 +320,19 @@ fn test_parser_mixed_all_cases() {
313
320
"# ,
314
321
) ,
315
322
] ;
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)
318
326
}
319
327
320
328
fn sloppy ( src : & str ) -> String {
321
329
src. replace ( ";" , "" )
322
330
}
323
331
324
- fn parse ( src : & str ) -> Vec < Expr > {
332
+ fn decode ( src : & str ) -> Vec < Expr > {
325
333
decode:: expr ( ) . parse ( src) . into_result ( ) . unwrap ( )
326
334
}
327
335
328
- fn encode ( ast : Vec < Expr > ) -> String {
336
+ fn encode ( ast : & [ Expr ] ) -> String {
329
337
encode:: expr ( ast) . collect ( )
330
338
}
0 commit comments