Commit | Line | Data |
---|---|---|
6d0e674a RS |
1 | #!/bin/sh |
2 | ||
3 | test_description='diff hunk fusing' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | f() { | |
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 | ||
18 | t() { | |
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 | ||
46 | cat <<EOF >expected.f1.0.1 || exit 1 | |
47 | diff --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 | |
56 | EOF | |
57 | ||
58 | cat <<EOF >expected.f1.0.2 || exit 1 | |
59 | diff --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 | |
68 | EOF | |
69 | ||
70 | # common lines ctx intrctx hunks | |
71 | t 1 line 0 2 | |
72 | t 1 line 0 0 2 | |
73 | t 1 line 0 1 1 | |
74 | t 1 line 0 2 1 | |
75 | t 1 line 1 1 | |
76 | ||
77 | t 2 lines 0 2 | |
78 | t 2 lines 0 0 2 | |
79 | t 2 lines 0 1 2 | |
80 | t 2 lines 0 2 1 | |
81 | t 2 lines 1 1 | |
82 | ||
83 | t 3 lines 1 2 | |
84 | t 3 lines 1 0 2 | |
85 | t 3 lines 1 1 1 | |
86 | t 3 lines 1 2 1 | |
87 | ||
88 | t 9 lines 3 2 | |
89 | t 9 lines 3 2 2 | |
90 | t 9 lines 3 3 1 | |
91 | ||
92 | test_done |