@@ -65,6 +65,33 @@ pub fn print_hexdump(bytes: impl AsRef<[u8]>, line_lengths: impl AsRef<[usize]>)
65
65
output
66
66
}
67
67
68
+ /// This is a macro to assert that two byte slices are equal.
69
+ ///
70
+ /// It is like assert_eq!, but it will print a nicely formatted hexdump of the
71
+ /// two slices if they are not equal. This makes it much easier to track down
72
+ /// a difference in a large byte slice.
73
+ #[ macro_export]
74
+ macro_rules! assert_eq_hex {
75
+ ( $a: expr, $b: expr) => {
76
+ assert_eq_hex!( $a, $b, [ ] )
77
+ } ;
78
+ ( $a: expr, $b: expr, $hint: expr) => {
79
+ let a = $a;
80
+ let b = $b;
81
+ let hint = $hint;
82
+ let ar: & [ u8 ] = a. as_ref( ) ;
83
+ let br: & [ u8 ] = b. as_ref( ) ;
84
+ let hintr: & [ usize ] = hint. as_ref( ) ;
85
+ if ar != br {
86
+ panic!(
87
+ "assertion failed: `(left == right)`\n left:\n {}\n right:\n {}\n " ,
88
+ :: iroh_test:: hexdump:: print_hexdump( ar, hintr) ,
89
+ :: iroh_test:: hexdump:: print_hexdump( br, hintr) ,
90
+ )
91
+ }
92
+ } ;
93
+ }
94
+
68
95
#[ cfg( test) ]
69
96
mod tests {
70
97
use super :: { parse_hexdump, print_hexdump} ;
@@ -151,30 +178,3 @@ mod tests {
151
178
assert_eq ! ( output, "01\n \n \n 02 03\n 04 05\n 06 07\n 08\n " ) ;
152
179
}
153
180
}
154
-
155
- /// This is a macro to assert that two byte slices are equal.
156
- ///
157
- /// It is like assert_eq!, but it will print a nicely formatted hexdump of the
158
- /// two slices if they are not equal. This makes it much easier to track down
159
- /// a difference in a large byte slice.
160
- #[ macro_export]
161
- macro_rules! assert_eq_hex {
162
- ( $a: expr, $b: expr) => {
163
- assert_eq_hex!( $a, $b, [ ] )
164
- } ;
165
- ( $a: expr, $b: expr, $hint: expr) => {
166
- let a = $a;
167
- let b = $b;
168
- let hint = $hint;
169
- let ar: & [ u8 ] = a. as_ref( ) ;
170
- let br: & [ u8 ] = b. as_ref( ) ;
171
- let hintr: & [ usize ] = hint. as_ref( ) ;
172
- if ar != br {
173
- panic!(
174
- "assertion failed: `(left == right)`\n left:\n {}\n right:\n {}\n " ,
175
- :: iroh_test:: hexdump:: print_hexdump( ar, hintr) ,
176
- :: iroh_test:: hexdump:: print_hexdump( br, hintr) ,
177
- )
178
- }
179
- } ;
180
- }
0 commit comments