@@ -21,65 +21,75 @@ impl Parse for ConditionClosure {
2121}
2222
2323pub fn assert_contract_eq ( left : & Contract , right : & Contract ) {
24- assert_conditions_eq ( & left. requires , & right. requires , "requires" ) ;
25- assert_conditions_eq ( & left. maintains , & right. maintains , "maintains" ) ;
26- assert_condition_closures_eq ( & left. ensures , & right. ensures , "ensures" ) ;
24+ assert_slice_eq (
25+ & left. requires ,
26+ & right. requires ,
27+ "requires" ,
28+ & assert_condition_eq,
29+ ) ;
30+ assert_slice_eq (
31+ & left. maintains ,
32+ & right. maintains ,
33+ "maintains" ,
34+ & assert_condition_eq,
35+ ) ;
36+ assert_slice_eq (
37+ & left. ensures ,
38+ & right. ensures ,
39+ "ensures" ,
40+ & assert_condition_closure_eq,
41+ ) ;
2742}
2843
29- fn assert_conditions_eq ( left : & [ Condition ] , right : & [ Condition ] , clause_name : & str ) {
44+ fn assert_slice_eq < T , F > ( left : & [ T ] , right : & [ T ] , item_name : & str , assert_item_eq : F )
45+ where
46+ F : Fn ( & T , & T , & str ) ,
47+ {
3048 assert_eq ! (
3149 left. len( ) ,
3250 right. len( ) ,
33- "number of {} clauses do not match" ,
34- clause_name
51+ "number of `{}` items do not match" ,
52+ item_name
3553 ) ;
3654
3755 for ( i, ( left_item, right_item) ) in left. iter ( ) . zip ( right. iter ( ) ) . enumerate ( ) {
38- assert_eq ! (
39- left_item. cfg. to_token_stream( ) . to_string( ) ,
40- right_item. cfg. to_token_stream( ) . to_string( ) ,
41- "{} clause #{} cfg does not match" ,
42- clause_name,
43- i + 1
44- ) ;
45-
46- assert_eq ! (
47- left_item. expr. to_token_stream( ) . to_string( ) ,
48- right_item. expr. to_token_stream( ) . to_string( ) ,
49- "{} clause #{} does not match" ,
50- clause_name,
51- i + 1
52- ) ;
56+ let msg_prefix = format ! ( "`{}` items at index {}, " , item_name, i) ;
57+ assert_item_eq ( left_item, right_item, & msg_prefix) ;
5358 }
5459}
5560
56- fn assert_condition_closures_eq (
57- left : & [ ConditionClosure ] ,
58- right : & [ ConditionClosure ] ,
59- clause_name : & str ,
60- ) {
61+ fn assert_condition_eq ( left : & Condition , right : & Condition , msg_prefix : & str ) {
6162 assert_eq ! (
62- left. len ( ) ,
63- right. len ( ) ,
64- "number of {} clauses do not match" ,
65- clause_name
63+ left. expr . to_token_stream ( ) . to_string ( ) ,
64+ right. expr . to_token_stream ( ) . to_string ( ) ,
65+ "{}`expr` does not match" ,
66+ msg_prefix
6667 ) ;
6768
68- for ( i, ( left_item, right_item) ) in left. iter ( ) . zip ( right. iter ( ) ) . enumerate ( ) {
69- assert_eq ! (
70- left_item. cfg. to_token_stream( ) . to_string( ) ,
71- right_item. cfg. to_token_stream( ) . to_string( ) ,
72- "{} clause #{} cfg does not match" ,
73- clause_name,
74- i + 1
75- ) ;
69+ assert_eq ! (
70+ left. cfg. to_token_stream( ) . to_string( ) ,
71+ right. cfg. to_token_stream( ) . to_string( ) ,
72+ "{}`cfg` does not match" ,
73+ msg_prefix
74+ ) ;
75+ }
7676
77- assert_eq ! (
78- left_item. closure. to_token_stream( ) . to_string( ) ,
79- right_item. closure. to_token_stream( ) . to_string( ) ,
80- "{} clause #{} does not match" ,
81- clause_name,
82- i + 1
83- ) ;
84- }
77+ fn assert_condition_closure_eq (
78+ left : & ConditionClosure ,
79+ right : & ConditionClosure ,
80+ msg_prefix : & str ,
81+ ) {
82+ assert_eq ! (
83+ left. closure. to_token_stream( ) . to_string( ) ,
84+ right. closure. to_token_stream( ) . to_string( ) ,
85+ "{}`closure` does not match" ,
86+ msg_prefix
87+ ) ;
88+
89+ assert_eq ! (
90+ left. cfg. to_token_stream( ) . to_string( ) ,
91+ right. cfg. to_token_stream( ) . to_string( ) ,
92+ "{}`cfg` does not match" ,
93+ msg_prefix
94+ ) ;
8595}
0 commit comments