@@ -12,10 +12,6 @@ cat << EOF > diff
1212-A
1313+a
1414+b
15- @@ -10 +11,2 @@
16- -C
17- +c
18- +d
1915--- file2
2016+++ file2
2117@@ -5 +5,2 @@
@@ -26,40 +22,69 @@ cat << EOF > diff
2622-G
2723+g
2824+h
25+ --- file3
26+ +++ file3
27+ @@ -10 +10,2 @@
28+ -I
29+ +i
30+ +j
31+ @@ -15 +16,2 @@
32+ -K
33+ +k
34+ +l
35+ @@ -25 +27,2 @@
36+ -M
37+ +m
38+ +n
2939EOF
3040
31- # Test --hunks 1 (first hunk from each file )
41+ # Test --hunks 1 (first hunk - all files have at least 1 hunk )
3242${LSDIFF} --hunks 1 diff 2> errors > hunks1 || exit 1
3343[ -s errors ] && exit 1
3444
3545cat << EOF | cmp - hunks1 || exit 1
3646file1
3747file2
48+ file3
3849EOF
3950
40- # Test --hunks 2 (second hunk from each file )
51+ # Test --hunks 2 (second hunk - only file2 and file3 have 2+ hunks )
4152${LSDIFF} --hunks 2 diff 2> errors > hunks2 || exit 1
4253[ -s errors ] && exit 1
4354
4455cat << EOF | cmp - hunks2 || exit 1
45- file1
4656file2
57+ file3
4758EOF
4859
49- # Test --hunks 3 (third hunk - lsdiff still shows files even if hunks don't match )
60+ # Test --hunks 3 (third hunk - only file3 has 3 hunks)
5061${LSDIFF} --hunks 3 diff 2> errors > hunks3 || exit 1
5162[ -s errors ] && exit 1
5263
5364cat << EOF | cmp - hunks3 || exit 1
54- file1
55- file2
65+ file3
5666EOF
5767
58- # Test --hunks 1-2 (range: first and second hunks)
68+ # Test --hunks 1-2 (range: first and second hunks - all files have hunk 1, file2 and file3 have hunk 2 )
5969${LSDIFF} --hunks 1-2 diff 2> errors > hunks1-2 || exit 1
6070[ -s errors ] && exit 1
6171
6272cat << EOF | cmp - hunks1-2 || exit 1
6373file1
6474file2
75+ file3
76+ EOF
77+
78+ # Test --hunks 2-3 (range: second and third hunks - file2 has hunk 2, file3 has hunks 2 and 3)
79+ ${LSDIFF} --hunks 2-3 diff 2> errors > hunks2-3 || exit 1
80+ [ -s errors ] && exit 1
81+
82+ cat << EOF | cmp - hunks2-3 || exit 1
83+ file2
84+ file3
6585EOF
86+
87+ # Test --hunks 4 (fourth hunk - no files have 4 hunks, should be empty)
88+ ${LSDIFF} --hunks 4 diff 2> errors > hunks4 || exit 1
89+ [ -s errors ] && exit 1
90+ [ -s hunks4 ] && exit 1 # Should be empty
0 commit comments