55
66use std:: io:: Write ;
77
8+ use crate :: utils:: do_write_line;
9+
810#[ derive( Debug , PartialEq ) ]
911struct Mismatch {
1012 pub line_number_expected : usize ,
@@ -114,7 +116,7 @@ fn make_diff(expected: &[u8], actual: &[u8], stop_early: bool) -> Vec<Mismatch>
114116}
115117
116118#[ must_use]
117- pub fn diff ( expected : & [ u8 ] , actual : & [ u8 ] , stop_early : bool ) -> Vec < u8 > {
119+ pub fn diff ( expected : & [ u8 ] , actual : & [ u8 ] , stop_early : bool , expand_tabs : bool ) -> Vec < u8 > {
118120 // See https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Normal.html
119121 // for details on the syntax of the normal format.
120122 let mut output = Vec :: new ( ) ;
@@ -188,7 +190,7 @@ pub fn diff(expected: &[u8], actual: &[u8], stop_early: bool) -> Vec<u8> {
188190 }
189191 for expected in & result. expected {
190192 write ! ( & mut output, "< " ) . unwrap ( ) ;
191- output . write_all ( expected) . unwrap ( ) ;
193+ do_write_line ( & mut output , expected, expand_tabs ) . unwrap ( ) ;
192194 writeln ! ( & mut output) . unwrap ( ) ;
193195 }
194196 if result. expected_missing_nl {
@@ -199,7 +201,7 @@ pub fn diff(expected: &[u8], actual: &[u8], stop_early: bool) -> Vec<u8> {
199201 }
200202 for actual in & result. actual {
201203 write ! ( & mut output, "> " ) . unwrap ( ) ;
202- output . write_all ( actual) . unwrap ( ) ;
204+ do_write_line ( & mut output , actual, expand_tabs ) . unwrap ( ) ;
203205 writeln ! ( & mut output) . unwrap ( ) ;
204206 }
205207 if result. actual_missing_nl {
@@ -220,7 +222,7 @@ mod tests {
220222 a. write_all ( b"a\n " ) . unwrap ( ) ;
221223 let mut b = Vec :: new ( ) ;
222224 b. write_all ( b"b\n " ) . unwrap ( ) ;
223- let diff = diff ( & a, & b, false ) ;
225+ let diff = diff ( & a, & b, false , false ) ;
224226 let expected = b"1c1\n < a\n ---\n > b\n " . to_vec ( ) ;
225227 assert_eq ! ( diff, expected) ;
226228 }
@@ -273,7 +275,7 @@ mod tests {
273275 }
274276 // This test diff is intentionally reversed.
275277 // We want it to turn the alef into bet.
276- let diff = diff ( & alef, & bet, false ) ;
278+ let diff = diff ( & alef, & bet, false , false ) ;
277279 File :: create ( & format ! ( "{target}/ab.diff" ) )
278280 . unwrap ( )
279281 . write_all ( & diff)
@@ -365,7 +367,7 @@ mod tests {
365367 }
366368 // This test diff is intentionally reversed.
367369 // We want it to turn the alef into bet.
368- let diff = diff ( & alef, & bet, false ) ;
370+ let diff = diff ( & alef, & bet, false , false ) ;
369371 File :: create ( & format ! ( "{target}/abn.diff" ) )
370372 . unwrap ( )
371373 . write_all ( & diff)
@@ -439,7 +441,7 @@ mod tests {
439441 }
440442 // This test diff is intentionally reversed.
441443 // We want it to turn the alef into bet.
442- let diff = diff ( & alef, & bet, false ) ;
444+ let diff = diff ( & alef, & bet, false , false ) ;
443445 File :: create ( & format ! ( "{target}/ab_.diff" ) )
444446 . unwrap ( )
445447 . write_all ( & diff)
@@ -517,7 +519,7 @@ mod tests {
517519 }
518520 // This test diff is intentionally reversed.
519521 // We want it to turn the alef into bet.
520- let diff = diff ( & alef, & bet, false ) ;
522+ let diff = diff ( & alef, & bet, false , false ) ;
521523 File :: create ( & format ! ( "{target}/abr.diff" ) )
522524 . unwrap ( )
523525 . write_all ( & diff)
@@ -552,18 +554,18 @@ mod tests {
552554 let from = [ "a" , "b" , "c" ] . join ( "\n " ) ;
553555 let to = [ "a" , "d" , "c" ] . join ( "\n " ) ;
554556
555- let diff_full = diff ( from. as_bytes ( ) , to. as_bytes ( ) , false ) ;
557+ let diff_full = diff ( from. as_bytes ( ) , to. as_bytes ( ) , false , false ) ;
556558 let expected_full = [ "2c2" , "< b" , "---" , "> d" , "" ] . join ( "\n " ) ;
557559 assert_eq ! ( diff_full, expected_full. as_bytes( ) ) ;
558560
559- let diff_brief = diff ( from. as_bytes ( ) , to. as_bytes ( ) , true ) ;
561+ let diff_brief = diff ( from. as_bytes ( ) , to. as_bytes ( ) , true , false ) ;
560562 let expected_brief = "\0 " . as_bytes ( ) ;
561563 assert_eq ! ( diff_brief, expected_brief) ;
562564
563- let nodiff_full = diff ( from. as_bytes ( ) , from. as_bytes ( ) , false ) ;
565+ let nodiff_full = diff ( from. as_bytes ( ) , from. as_bytes ( ) , false , false ) ;
564566 assert ! ( nodiff_full. is_empty( ) ) ;
565567
566- let nodiff_brief = diff ( from. as_bytes ( ) , from. as_bytes ( ) , true ) ;
568+ let nodiff_brief = diff ( from. as_bytes ( ) , from. as_bytes ( ) , true , false ) ;
567569 assert ! ( nodiff_brief. is_empty( ) ) ;
568570 }
569571}
0 commit comments