@@ -263,7 +263,8 @@ mod tests {
263263 fn test_retrieve_contract_variables ( ) {
264264 let mut path = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
265265 path. push ( "tests" ) ;
266- path. push ( "good.sol" ) ;
266+ path. push ( "variables" ) ;
267+ path. push ( "contract.sol" ) ;
267268 let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
268269 let source = fs:: read_to_string ( & path) . unwrap ( ) ;
269270
@@ -309,6 +310,7 @@ mod tests {
309310 fn test_retrieve_file_variables ( ) {
310311 let mut path = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
311312 path. push ( "tests" ) ;
313+ path. push ( "variables" ) ;
312314 path. push ( "file.sol" ) ;
313315 let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
314316 let source = fs:: read_to_string ( & path) . unwrap ( ) ;
@@ -328,9 +330,73 @@ mod tests {
328330 }
329331
330332 #[ test]
331- fn test_retrieve_enums ( ) {
332- retrieve_file_reference_from_path ( "./tests/two.sol" . to_string ( ) ) ;
333- assert_eq ! ( 1 , 0 )
333+ fn test_retrieve_contract_enums ( ) {
334+ let mut path = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
335+ path. push ( "tests" ) ;
336+ path. push ( "enums" ) ;
337+ path. push ( "contract.sol" ) ;
338+ let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
339+ let source = fs:: read_to_string ( & path) . unwrap ( ) ;
340+
341+ let mut visitor = FileVisitor :: new ( path_str. clone ( ) ) ;
342+ let contract_ref = ContractReference :: new (
343+ "Good" . to_string ( ) ,
344+ Location :: new ( path_str, Bound { line : 1 , column : 1 } , Bound :: new ( 1 , 10 ) ) ,
345+ & visitor. file_reference ,
346+ ) ;
347+ visitor
348+ . file_reference
349+ . borrow_mut ( )
350+ . add_contract ( contract_ref) ;
351+ visitor. current_contract = Some ( visitor. file_reference . borrow ( ) . contracts [ 0 ] . clone ( ) ) ;
352+ let file = ast_extractor:: extract:: extract_ast_from ( source) . unwrap ( ) ;
353+ let contract = file. items . iter ( ) . find ( |item| match item {
354+ syn_solidity:: Item :: Contract ( contract) => true ,
355+ _ => false ,
356+ } ) ;
357+ let contract = match contract {
358+ Some ( syn_solidity:: Item :: Contract ( contract) ) => contract,
359+ _ => panic ! ( "No contract found" ) ,
360+ } ;
361+ let enums = contract. body . iter ( ) . find ( |item| match item {
362+ syn_solidity:: Item :: Enum ( _) => true ,
363+ _ => false ,
364+ } ) ;
365+ let enums = match enums {
366+ Some ( syn_solidity:: Item :: Enum ( enums) ) => enums,
367+ _ => panic ! ( "No enums found" ) ,
368+ } ;
369+ visitor. visit_item_enum ( enums) ;
370+ assert_eq ! (
371+ visitor. file_reference. borrow( ) . contracts[ 0 ]
372+ . borrow( )
373+ . properties
374+ . len( ) ,
375+ 1
376+ ) ;
377+ }
378+
379+ #[ test]
380+ fn test_retrieve_file_enums ( ) {
381+ let mut path = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
382+ path. push ( "tests" ) ;
383+ path. push ( "enums" ) ;
384+ path. push ( "file.sol" ) ;
385+ let path_str = path. to_str ( ) . unwrap ( ) . to_string ( ) ;
386+ let source = fs:: read_to_string ( & path) . unwrap ( ) ;
387+
388+ let mut visitor = FileVisitor :: new ( path_str. clone ( ) ) ;
389+ let file = ast_extractor:: extract:: extract_ast_from ( source) . unwrap ( ) ;
390+ let enums = file. items . iter ( ) . find ( |item| match item {
391+ syn_solidity:: Item :: Enum ( contract) => true ,
392+ _ => false ,
393+ } ) ;
394+ let enums = match enums {
395+ Some ( syn_solidity:: Item :: Enum ( var) ) => var,
396+ _ => panic ! ( "Expect enums declaration" ) ,
397+ } ;
398+ visitor. visit_item_enum ( enums) ;
399+ assert_eq ! ( visitor. file_reference. borrow( ) . enums. len( ) , 1 ) ;
334400 }
335401
336402 #[ test]
0 commit comments