11use libxml:: parser:: Parser ;
22use libxml:: tree:: c14n:: { CanonicalizationMode , CanonicalizationOptions } ;
33
4+ fn assert_eq_lines ( seen : & str , expected : & str ) {
5+ let lines_iter = seen. lines ( ) . zip ( expected. lines ( ) ) ;
6+
7+ for ( seen_line, expected_line) in lines_iter {
8+ assert_eq ! ( seen_line, expected_line) ;
9+ }
10+
11+ assert_eq ! ( seen. lines( ) . count( ) , expected. lines( ) . count( ) ) ;
12+ }
13+
414fn canonicalize_xml ( input : & str , opts : CanonicalizationOptions ) -> String {
515 let parser = Parser :: default ( ) ;
616 let doc = parser. parse_string ( input) . unwrap ( ) ;
@@ -21,7 +31,8 @@ fn canonical_1_1_example_3_1_no_comment() {
2131 inclusive_ns_prefixes : vec ! [ ] ,
2232 } ,
2333 ) ;
24- assert_eq ! ( canonicalized, expected)
34+
35+ assert_eq_lines ( & canonicalized, expected) ;
2536}
2637
2738#[ test]
@@ -39,7 +50,7 @@ fn canonical_1_1_example_3_2() {
3950 ) ;
4051
4152 // for some reason, we get a stray \n at end of file :/
42- assert_eq ! ( canonicalized, expected. trim( ) )
53+ assert_eq_lines ( & canonicalized, expected. trim ( ) )
4354}
4455
4556#[ test]
@@ -57,7 +68,7 @@ fn canonical_exclusive_example_1() {
5768 ) ;
5869
5970 // for some reason, we get a stray \n at end of file :/
60- assert_eq ! ( canonicalized, expected. trim( ) )
71+ assert_eq_lines ( & canonicalized, expected. trim ( ) )
6172}
6273
6374#[ test]
@@ -75,7 +86,7 @@ fn canonical_exclusive_example_2() {
7586 ) ;
7687
7788 // for some reason, we get a stray \n at end of file :/
78- assert_eq ! ( canonicalized, expected. trim( ) )
89+ assert_eq_lines ( & canonicalized, expected. trim ( ) )
7990}
8091
8192#[ test]
@@ -140,7 +151,7 @@ fn test_c14n_modes() {
140151 </n1:elem2>
141152 "# . trim ( ) ;
142153 let c14n = node1. canonicalize ( opts ( ) ) . unwrap ( ) ;
143- assert_eq ! ( expected, c14n) ;
154+ assert_eq_lines ( expected, & c14n) ;
144155
145156 let expected = r#"
146157 <n1:elem2 xmlns:n1="http://example.net" xmlns:n2="http://foo.example" xmlns:n4="http://foo.example" xml:lang="en" xml:space="retain">
@@ -149,14 +160,14 @@ fn test_c14n_modes() {
149160 </n1:elem2>
150161 "# . trim ( ) ;
151162 let c14n = node2. canonicalize ( opts ( ) ) . unwrap ( ) ;
152- assert_eq ! ( expected, c14n) ;
163+ assert_eq_lines ( & expected, & c14n) ;
153164
154165 let opts = CanonicalizationOptions {
155166 mode : CanonicalizationMode :: Canonical1_0 ,
156167 ..Default :: default ( )
157168 } ;
158169 let c14n = node2. canonicalize ( opts) . unwrap ( ) ;
159- assert_eq ! ( expected, c14n) ;
170+ assert_eq_lines ( expected, & c14n) ;
160171
161172 let expected = r#"
162173 <n1:elem2 xmlns:n1="http://example.net" xml:lang="en">
@@ -171,7 +182,7 @@ fn test_c14n_modes() {
171182 } )
172183 . unwrap ( ) ;
173184
174- assert_eq ! ( expected, c14n) ;
185+ assert_eq_lines ( expected, & c14n) ;
175186
176187 let expected = r#"
177188 <n1:elem2 xmlns:n1="http://example.net" xml:lang="en">
@@ -186,7 +197,7 @@ fn test_c14n_modes() {
186197 ..Default :: default ( )
187198 } )
188199 . unwrap ( ) ;
189- assert_eq ! ( expected, c14n) ;
200+ assert_eq_lines ( expected, & c14n) ;
190201
191202 let expected = r#"
192203 <n1:elem2 xmlns:n1="http://example.net" xmlns:n2="http://foo.example" xml:lang="en">
@@ -202,7 +213,7 @@ fn test_c14n_modes() {
202213 ..Default :: default ( )
203214 } )
204215 . unwrap ( ) ;
205- assert_eq ! ( expected, c14n) ;
216+ assert_eq_lines ( expected, & c14n) ;
206217
207218 let expected = r#"
208219 <n1:elem2 xmlns:n1="http://example.net" xmlns:n2="http://foo.example" xmlns:n4="http://foo.example" xml:lang="en">
@@ -217,7 +228,7 @@ fn test_c14n_modes() {
217228 ..Default :: default ( )
218229 } )
219230 . unwrap ( ) ;
220- assert_eq ! ( expected, c14n) ;
231+ assert_eq_lines ( expected, & c14n) ;
221232
222233 let expected = r#"
223234 <n1:elem2 xmlns:n1="http://example.net" xmlns:n2="http://foo.example" xmlns:n4="http://foo.example" xml:lang="en" xml:space="retain">
@@ -231,7 +242,7 @@ fn test_c14n_modes() {
231242 ..Default :: default ( )
232243 } )
233244 . unwrap ( ) ;
234- assert_eq ! ( expected, c14n) ;
245+ assert_eq_lines ( expected, & c14n) ;
235246}
236247
237248fn opts ( ) -> CanonicalizationOptions {
0 commit comments