File tree Expand file tree Collapse file tree 1 file changed +66
-2
lines changed Expand file tree Collapse file tree 1 file changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -413,16 +413,80 @@ mod diff {
413413 type Out = usize ;
414414
415415 fn process_change ( & mut self , before : Range < u32 > , _after : Range < u32 > ) {
416- self . removed_bytes = self . input . before [ before. start as usize ..before. end as usize ]
416+ self . removed_bytes + = self . input . before [ before. start as usize ..before. end as usize ]
417417 . iter ( )
418418 . map ( |token| self . input . interner [ * token] . len ( ) )
419- . sum ( ) ;
419+ . sum :: < usize > ( ) ;
420420 }
421421
422422 fn finish ( self ) -> Self :: Out {
423423 self . removed_bytes
424424 }
425425 }
426+
427+ #[ cfg( test) ]
428+ mod tests {
429+ fn removed_bytes ( before : & [ u8 ] , after : & [ u8 ] ) -> usize {
430+ let input = gix_diff:: blob:: intern:: InternedInput :: new ( before, after) ;
431+ gix_diff:: blob:: diff (
432+ gix_diff:: blob:: Algorithm :: Myers ,
433+ & input,
434+ super :: Statistics {
435+ removed_bytes : 0 ,
436+ input : & input,
437+ } ,
438+ )
439+ }
440+
441+ #[ test]
442+ fn counts_removed_bytes_correctly ( ) {
443+ assert_eq ! ( 1 , removed_bytes( b"a" , b"" ) ) ;
444+ assert_eq ! ( 0 , removed_bytes( b"" , b"a" ) ) ;
445+
446+ // need the inputs to have more than one "hunk"
447+ // of differences to stress the fact that
448+ // process_change is called multiple times
449+ let before = b"
450+ a
451+ a
452+ a
453+ b
454+ b
455+ b
456+ b
457+ a
458+ a
459+ a
460+ a
461+ a
462+ b
463+ b
464+ a
465+ a
466+ a
467+ a
468+ a
469+ " ;
470+ // it's `before`, with the "b" lines removed
471+ let after = b"
472+ a
473+ a
474+ a
475+ a
476+ a
477+ a
478+ a
479+ a
480+ a
481+ a
482+ a
483+ a
484+ a
485+ " ;
486+
487+ assert_eq ! ( 6 , removed_bytes( before, after) ) ;
488+ }
489+ }
426490}
427491
428492mod tree_to_events {
You can’t perform that action at this time.
0 commit comments