1#!/bin/sh
2
3test_description='diff hunk fusing'
4
5. ./test-lib.sh
6
7f() {
8 echo $1
9 i=1
10 while test $i -le $2
11 do
12 echo $i
13 i=$(expr $i + 1)
14 done
15 echo $3
16}
17
18t() {
19 case $# in
20 4) hunks=$4; cmd="diff -U$3";;
21 5) hunks=$5; cmd="diff -U$3 --inter-hunk-context=$4";;
22 esac
23 label="$cmd, $1 common $2"
24 file=f$1
25 expected=expected.$file.$3.$hunks
26
27 if ! test -f $file
28 then
29 f A $1 B >$file
30 git add $file
31 git commit -q -m. $file
32 f X $1 Y >$file
33 fi
34
35 test_expect_success "$label: count hunks ($hunks)" "
36 test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
37 "
38
39 test -f $expected &&
40 test_expect_success "$label: check output" "
41 git $cmd $file | grep -v '^index ' >actual &&
42 test_cmp $expected actual
43 "
44}
45
46cat <<EOF >expected.f1.0.1 || exit 1
47diff --git a/f1 b/f1
48--- a/f1
49+++ b/f1
50@@ -1,3 +1,3 @@
51-A
52+X
53 1
54-B
55+Y
56EOF
57
58cat <<EOF >expected.f1.0.2 || exit 1
59diff --git a/f1 b/f1
60--- a/f1
61+++ b/f1
62@@ -1 +1 @@
63-A
64+X
65@@ -3 +3 @@ A
66-B
67+Y
68EOF
69
70# common lines ctx intrctx hunks
71t 1 line 0 2
72t 1 line 0 0 2
73t 1 line 0 1 1
74t 1 line 0 2 1
75t 1 line 1 1
76
77t 2 lines 0 2
78t 2 lines 0 0 2
79t 2 lines 0 1 2
80t 2 lines 0 2 1
81t 2 lines 1 1
82
83t 3 lines 1 2
84t 3 lines 1 0 2
85t 3 lines 1 1 1
86t 3 lines 1 2 1
87
88t 9 lines 3 2
89t 9 lines 3 2 2
90t 9 lines 3 3 1
91
92test_done