diff --git a/test/fixtures/complex-hunks.diff b/test/fixtures/complex-hunks.diff new file mode 100644 index 0000000..f02e035 --- /dev/null +++ b/test/fixtures/complex-hunks.diff @@ -0,0 +1,32 @@ +commit 74804e377d4a54d1173d4393827d4e4b27e4d5d0 +diff --cc libs/header_clean/header_clean.pl +index e8bcd92,5970580..ae279d0 +--- a/libs/header_clean/header_clean.pl ++++ b/libs/header_clean/header_clean.pl +@@@ -105,13 -104,21 +104,23 @@@ for (my $i = 0; $i <= $#input; $i++)  + } + } +  ++ # Courtesy of github.com/git/git/blob/ab5d01a/git-add--interactive.perl#L798-L805 ++ sub parse_hunk_header { ++ my ($line) = @_; ++ my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) = ++ $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/; ++ $o_cnt = 1 unless defined $o_cnt; ++ $n_cnt = 1 unless defined $n_cnt; ++ return ($o_ofs, $o_cnt, $n_ofs, $n_cnt); ++ } ++  + sub strip_empty_first_line { + - my $foo = shift(); # Array passed in by reference + + my $array = shift(); # Array passed in by reference +  + # If the first line is just whitespace remove it + - if (defined($foo->[0]) && $foo->[0] =~ /^\s*$/) { + - shift($foo); + + if (defined($array->[0]) && $array->[0] =~ /^\s*$/) { + + shift(@$array); # Throw away the first line + } + + + + return 1; + } diff --git a/test/header_clean.bats b/test/header_clean.bats index a00d35d..61b2e3e 100644 --- a/test/header_clean.bats +++ b/test/header_clean.bats @@ -56,6 +56,20 @@ output=$( load_fixture "file-moves" | $diff_so_fancy ) assert_output --partial '@ diff-so-fancy:3 @' } +@test "Hunk formatting: @@@ -A,B -C,D +E,F @@@" { + # stderr forced into output + output=$( load_fixture "complex-hunks" | $diff_so_fancy 2>&1 ) + assert_output --partial '@ header_clean.pl:107 @' + refute_output --partial 'Use of uninitialized value' +} + +@test "+/- symbols are stripped (complex-hunks on git show)" { + output=$( load_fixture "complex-hunks" | $diff_so_fancy) + lines=$( printf "%s" "$output") + run printf "%s" "$lines" + refute_line --index 29 "+ return 1;" +} + @test "mnemonicprefix handling" { output=$( load_fixture "mnemonicprefix" | $diff_so_fancy ) assert_output --partial 'modified: test/header_clean.bats'