66use std:: collections:: VecDeque ;
77use std:: io:: Write ;
88
9+ use crate :: params:: Params ;
910use crate :: utils:: do_write_line;
1011
1112#[ derive( Debug , PartialEq ) ]
@@ -265,23 +266,18 @@ fn make_diff(
265266}
266267
267268#[ must_use]
268- #[ allow( clippy:: too_many_arguments) ]
269- pub fn diff (
270- expected : & [ u8 ] ,
271- expected_filename : & str ,
272- actual : & [ u8 ] ,
273- actual_filename : & str ,
274- context_size : usize ,
275- stop_early : bool ,
276- expand_tabs : bool ,
277- tabsize : usize ,
278- ) -> Vec < u8 > {
279- let mut output = format ! ( "*** {expected_filename}\t \n --- {actual_filename}\t \n " ) . into_bytes ( ) ;
280- let diff_results = make_diff ( expected, actual, context_size, stop_early) ;
269+ pub fn diff ( expected : & [ u8 ] , actual : & [ u8 ] , params : & Params ) -> Vec < u8 > {
270+ let mut output = format ! (
271+ "*** {0}\t \n --- {1}\t \n " ,
272+ params. from. to_string_lossy( ) ,
273+ params. to. to_string_lossy( )
274+ )
275+ . into_bytes ( ) ;
276+ let diff_results = make_diff ( expected, actual, params. context_count , params. brief ) ;
281277 if diff_results. is_empty ( ) {
282278 return Vec :: new ( ) ;
283279 }
284- if stop_early {
280+ if params . brief {
285281 return output;
286282 }
287283 for result in diff_results {
@@ -319,19 +315,19 @@ pub fn diff(
319315 match line {
320316 DiffLine :: Context ( e) => {
321317 write ! ( output, " " ) . expect ( "write to Vec is infallible" ) ;
322- do_write_line ( & mut output, & e, expand_tabs, tabsize)
318+ do_write_line ( & mut output, & e, params . expand_tabs , params . tabsize )
323319 . expect ( "write to Vec is infallible" ) ;
324320 writeln ! ( output) . unwrap ( ) ;
325321 }
326322 DiffLine :: Change ( e) => {
327323 write ! ( output, "! " ) . expect ( "write to Vec is infallible" ) ;
328- do_write_line ( & mut output, & e, expand_tabs, tabsize)
324+ do_write_line ( & mut output, & e, params . expand_tabs , params . tabsize )
329325 . expect ( "write to Vec is infallible" ) ;
330326 writeln ! ( output) . unwrap ( ) ;
331327 }
332328 DiffLine :: Add ( e) => {
333329 write ! ( output, "- " ) . expect ( "write to Vec is infallible" ) ;
334- do_write_line ( & mut output, & e, expand_tabs, tabsize)
330+ do_write_line ( & mut output, & e, params . expand_tabs , params . tabsize )
335331 . expect ( "write to Vec is infallible" ) ;
336332 writeln ! ( output) . unwrap ( ) ;
337333 }
@@ -349,19 +345,19 @@ pub fn diff(
349345 match line {
350346 DiffLine :: Context ( e) => {
351347 write ! ( output, " " ) . expect ( "write to Vec is infallible" ) ;
352- do_write_line ( & mut output, & e, expand_tabs, tabsize)
348+ do_write_line ( & mut output, & e, params . expand_tabs , params . tabsize )
353349 . expect ( "write to Vec is infallible" ) ;
354350 writeln ! ( output) . unwrap ( ) ;
355351 }
356352 DiffLine :: Change ( e) => {
357353 write ! ( output, "! " ) . expect ( "write to Vec is infallible" ) ;
358- do_write_line ( & mut output, & e, expand_tabs, tabsize)
354+ do_write_line ( & mut output, & e, params . expand_tabs , params . tabsize )
359355 . expect ( "write to Vec is infallible" ) ;
360356 writeln ! ( output) . unwrap ( ) ;
361357 }
362358 DiffLine :: Add ( e) => {
363359 write ! ( output, "+ " ) . expect ( "write to Vec is infallible" ) ;
364- do_write_line ( & mut output, & e, expand_tabs, tabsize)
360+ do_write_line ( & mut output, & e, params . expand_tabs , params . tabsize )
365361 . expect ( "write to Vec is infallible" ) ;
366362 writeln ! ( output) . unwrap ( ) ;
367363 }
@@ -430,13 +426,13 @@ mod tests {
430426 // We want it to turn the alef into bet.
431427 let diff = diff (
432428 & alef,
433- "a/alef" ,
434429 & bet,
435- & format ! ( "{target}/alef" ) ,
436- 2 ,
437- false ,
438- false ,
439- 8 ,
430+ & Params {
431+ from : "a/alef" . into ( ) ,
432+ to : ( & format ! ( "{target}/alef" ) ) . into ( ) ,
433+ context_count : 2 ,
434+ ..Default :: default ( )
435+ } ,
440436 ) ;
441437 File :: create ( & format ! ( "{target}/ab.diff" ) )
442438 . unwrap ( )
@@ -511,13 +507,13 @@ mod tests {
511507 // We want it to turn the alef into bet.
512508 let diff = diff (
513509 & alef,
514- "a/alef_" ,
515510 & bet,
516- & format ! ( "{target}/alef_" ) ,
517- 2 ,
518- false ,
519- false ,
520- 8 ,
511+ & Params {
512+ from : "a/alef_" . into ( ) ,
513+ to : ( & format ! ( "{target}/alef_" ) ) . into ( ) ,
514+ context_count : 2 ,
515+ ..Default :: default ( )
516+ } ,
521517 ) ;
522518 File :: create ( & format ! ( "{target}/ab_.diff" ) )
523519 . unwrap ( )
@@ -595,13 +591,13 @@ mod tests {
595591 // We want it to turn the alef into bet.
596592 let diff = diff (
597593 & alef,
598- "a/alefx" ,
599594 & bet,
600- & format ! ( "{target}/alefx" ) ,
601- 2 ,
602- false ,
603- false ,
604- 8 ,
595+ & Params {
596+ from : "a/alefx" . into ( ) ,
597+ to : ( & format ! ( "{target}/alefx" ) ) . into ( ) ,
598+ context_count : 2 ,
599+ ..Default :: default ( )
600+ } ,
605601 ) ;
606602 File :: create ( & format ! ( "{target}/abx.diff" ) )
607603 . unwrap ( )
@@ -682,13 +678,13 @@ mod tests {
682678 // We want it to turn the alef into bet.
683679 let diff = diff (
684680 & alef,
685- "a/alefr" ,
686681 & bet,
687- & format ! ( "{target}/alefr" ) ,
688- 2 ,
689- false ,
690- false ,
691- 8 ,
682+ & Params {
683+ from : "a/alefr" . into ( ) ,
684+ to : ( & format ! ( "{target}/alefr" ) ) . into ( ) ,
685+ context_count : 2 ,
686+ ..Default :: default ( )
687+ } ,
692688 ) ;
693689 File :: create ( & format ! ( "{target}/abr.diff" ) )
694690 . unwrap ( )
@@ -725,17 +721,15 @@ mod tests {
725721 let from = [ "a" , "b" , "c" , "" ] . join ( "\n " ) ;
726722 let to_filename = "bar" ;
727723 let to = [ "a" , "d" , "c" , "" ] . join ( "\n " ) ;
728- let context_size: usize = 3 ;
729724
730725 let diff_full = diff (
731726 from. as_bytes ( ) ,
732- from_filename,
733727 to. as_bytes ( ) ,
734- to_filename ,
735- context_size ,
736- false ,
737- false ,
738- 8 ,
728+ & Params {
729+ from : from_filename . into ( ) ,
730+ to : to_filename . into ( ) ,
731+ .. Default :: default ( )
732+ } ,
739733 ) ;
740734 let expected_full = [
741735 "*** foo\t " ,
@@ -756,38 +750,37 @@ mod tests {
756750
757751 let diff_brief = diff (
758752 from. as_bytes ( ) ,
759- from_filename,
760753 to. as_bytes ( ) ,
761- to_filename,
762- context_size,
763- true ,
764- false ,
765- 8 ,
754+ & Params {
755+ from : from_filename. into ( ) ,
756+ to : to_filename. into ( ) ,
757+ brief : true ,
758+ ..Default :: default ( )
759+ } ,
766760 ) ;
767761 let expected_brief = [ "*** foo\t " , "--- bar\t " , "" ] . join ( "\n " ) ;
768762 assert_eq ! ( diff_brief, expected_brief. as_bytes( ) ) ;
769763
770764 let nodiff_full = diff (
771765 from. as_bytes ( ) ,
772- from_filename,
773766 from. as_bytes ( ) ,
774- to_filename ,
775- context_size ,
776- false ,
777- false ,
778- 8 ,
767+ & Params {
768+ from : from_filename . into ( ) ,
769+ to : to_filename . into ( ) ,
770+ .. Default :: default ( )
771+ } ,
779772 ) ;
780773 assert ! ( nodiff_full. is_empty( ) ) ;
781774
782775 let nodiff_brief = diff (
783776 from. as_bytes ( ) ,
784- from_filename,
785777 from. as_bytes ( ) ,
786- to_filename,
787- context_size,
788- true ,
789- false ,
790- 8 ,
778+ & Params {
779+ from : from_filename. into ( ) ,
780+ to : to_filename. into ( ) ,
781+ brief : true ,
782+ ..Default :: default ( )
783+ } ,
791784 ) ;
792785 assert ! ( nodiff_brief. is_empty( ) ) ;
793786 }
0 commit comments