@@ -1146,22 +1146,61 @@ mod render {
1146
1146
}
1147
1147
}
1148
1148
1149
- impl TestsGroup {
1150
- pub fn get_test_functions ( & self ) -> Vec < ItemFn > {
1151
- let mut f = TestFunctions ( vec ! [ ] ) ;
1149
+ trait ModuleInspector {
1150
+ fn get_test_functions ( & self ) -> Vec < ItemFn > ;
1151
+ fn get_submodules ( & self ) -> Vec < ItemMod > ;
1152
+ }
1152
1153
1153
- f. visit_item_mod ( & self . module ) ;
1154
+ impl ModuleInspector for ItemMod {
1155
+ fn get_test_functions ( & self ) -> Vec < ItemFn > {
1156
+ let mut f = TestFunctions ( vec ! [ ] ) ;
1157
+ f. visit_item_mod ( & self ) ;
1154
1158
f. 0
1155
1159
}
1156
1160
1157
- pub fn get_submodules ( & self ) -> Vec < ItemMod > {
1161
+ fn get_submodules ( & self ) -> Vec < ItemMod > {
1158
1162
let mut f = SubModules ( vec ! [ ] ) ;
1159
1163
1160
- self . module . content . as_ref ( ) . map ( |( _, items) | items. iter ( ) . for_each ( |it| f. visit_item ( it) ) ) ;
1164
+ self . content . as_ref ( ) . map ( |( _, items) |
1165
+ items. iter ( ) . for_each ( |it| f. visit_item ( it) )
1166
+ ) ;
1161
1167
f. 0
1162
1168
}
1163
1169
}
1164
1170
1171
+ impl ModuleInspector for TestsGroup {
1172
+ fn get_test_functions ( & self ) -> Vec < ItemFn > {
1173
+ self . module . get_test_functions ( )
1174
+ }
1175
+
1176
+ fn get_submodules ( & self ) -> Vec < ItemMod > {
1177
+ self . module . get_submodules ( )
1178
+ }
1179
+ }
1180
+
1181
+ #[ derive( Default , Debug ) ]
1182
+ struct Assignments ( HashMap < String , syn:: Expr > ) ;
1183
+
1184
+ impl < ' ast > Visit < ' ast > for Assignments {
1185
+ //noinspection RsTypeCheck
1186
+ fn visit_local ( & mut self , assign : & syn:: Local ) {
1187
+ match & assign {
1188
+ syn:: Local { pat : syn:: Pat :: Ident ( pat) , init : Some ( ( _, expr) ) , .. } => {
1189
+ self . 0 . insert ( pat. ident . to_string ( ) , expr. as_ref ( ) . clone ( ) ) ;
1190
+ } ,
1191
+ _ => { }
1192
+ }
1193
+ }
1194
+ }
1195
+
1196
+ impl Assignments {
1197
+ pub fn collect_assignments ( item_fn : & ItemFn ) -> Self {
1198
+ let mut collect = Self :: default ( ) ;
1199
+ collect. visit_item_fn ( item_fn) ;
1200
+ collect
1201
+ }
1202
+ }
1203
+
1165
1204
impl From < TokenStream > for TestsGroup {
1166
1205
fn from ( tokens : TokenStream ) -> Self {
1167
1206
syn:: parse2 :: < TestsGroup > ( tokens) . unwrap ( )
@@ -1525,7 +1564,10 @@ mod render {
1525
1564
items : vec ! [ fixture( "fix" , vec![ "2" ] ) . into( ) ,
1526
1565
ident( "a" ) . into( ) , ident( "b" ) . into( ) ,
1527
1566
vec![ "1f64" , "2f32" ] . into_iter( ) . collect:: <TestCase >( ) . into( ) ,
1528
- vec![ "3f64" , "4f32" ] . into_iter( ) . collect:: <TestCase >( ) . into( ) ,
1567
+ TestCase {
1568
+ description: Some ( ident( "description" ) ) ,
1569
+ ..vec![ "3f64" , "4f32" ] . into_iter( ) . collect:: <TestCase >( )
1570
+ } . into( ) ,
1529
1571
values_list( "x" , & [ "12" , "-2" ] ) . into( ) ,
1530
1572
values_list( "y" , & [ "-3" , "42" ] ) . into( ) ,
1531
1573
] ,
@@ -1535,7 +1577,22 @@ mod render {
1535
1577
let output = TestsGroup :: from ( tokens) ;
1536
1578
1537
1579
assert_eq ! ( output. module. ident, "should_be_the_outer_module_name" ) ;
1538
- assert_eq ! ( 2 , output. get_submodules( ) . len( ) ) ;
1580
+
1581
+ let sub_modules = output. get_submodules ( ) ;
1582
+ assert_eq ! ( 2 , sub_modules. len( ) ) ;
1583
+
1584
+ assert_eq ! ( sub_modules[ 0 ] . ident, "case_1" ) ;
1585
+ assert_eq ! ( sub_modules[ 1 ] . ident, "case_2_description" ) ;
1586
+
1587
+ // 4 foreach modules
1588
+ assert_eq ! ( 4 , sub_modules[ 0 ] . get_test_functions( ) . len( ) ) ;
1589
+ assert_eq ! ( 4 , sub_modules[ 1 ] . get_test_functions( ) . len( ) ) ;
1590
+
1591
+ // No more
1592
+ assert_eq ! ( 8 , output. get_test_functions( ) . len( ) ) ;
1593
+
1594
+ dbg ! ( Assignments :: collect_assignments( & sub_modules[ 0 ] . get_test_functions( ) [ 0 ] ) ) ;
1595
+ assert ! ( false ) ;
1539
1596
}
1540
1597
}
1541
1598
0 commit comments