@@ -27,6 +27,7 @@ use cedar_policy_generators::{
27
27
use libfuzzer_sys:: arbitrary:: { self , Arbitrary , Unstructured } ;
28
28
use log:: debug;
29
29
use serde:: Serialize ;
30
+ use similar_asserts:: SimpleDiff ;
30
31
use smol_str:: SmolStr ;
31
32
use std:: collections:: HashMap ;
32
33
use uuid:: Uuid ;
@@ -104,12 +105,31 @@ fn round_trip(p: &StaticPolicy) -> Result<StaticPolicy, parser::err::ParseErrors
104
105
line_width : 80 ,
105
106
} ;
106
107
let mut uuids = Vec :: new ( ) ;
108
+ let commented = attach_comment ( & p. to_string ( ) , & mut uuids) ;
107
109
let formatted_policy_str =
108
- & policies_str_to_pretty ( & attach_comment ( & p. to_string ( ) , & mut uuids) , & config)
109
- . expect ( "pretty-printing should not fail" ) ;
110
+ & policies_str_to_pretty ( & commented, & config) . expect ( "pretty-printing should not fail" ) ;
110
111
// check if pretty-printing drops any comment
112
+ let mut formatted_policy_tail: & str = formatted_policy_str. as_str ( ) ;
111
113
for u in & uuids {
112
- assert ! ( formatted_policy_str. contains( u) , "missing comment: {}\n " , u) ;
114
+ match formatted_policy_tail. split_once ( u) {
115
+ Some ( ( _, after_uuid) ) => formatted_policy_tail = after_uuid,
116
+ None => {
117
+ println ! (
118
+ "{}" ,
119
+ SimpleDiff :: from_str(
120
+ & commented,
121
+ formatted_policy_str,
122
+ "Commented Policy" ,
123
+ "Commented and formatted"
124
+ )
125
+ ) ;
126
+ if formatted_policy_str. contains ( u) {
127
+ panic ! ( "It looks like we skipped over comment `{u}`. The formatter might have reordered the comment" )
128
+ } else {
129
+ panic ! ( "Failed to find comment `{u}` anywhere. The formatter might have dropped the comment" )
130
+ }
131
+ }
132
+ }
113
133
}
114
134
parse_policy ( None , formatted_policy_str)
115
135
}
0 commit comments