3 test_description
='check diff_added_lines finds all added lines'
9 test_expect_success
'diff generates dreaded "\ No newline at end of file"' '
10 printf "%s" "" >file1 &&
11 printf "%s" "newline" >file2 &&
13 diff --git file1 file2
14 index e69de29bb2d1d643..8010d218a3d3561b 100644
19 \\ No newline at end of file
21 test_expect_code 1 test_diff file1 file2 >actual &&
22 test_diff expected actual
25 # if $3 is non-empty use --ignore-space-at-eol
27 printf "%s" "$1" >file1
&&
28 printf "%s" "$2" >file2
&&
30 test_diff
${3:+--ignore-space-at-eol} file1 file2 || ec_
=$?
31 test $ec_ -eq 0 ||
test $ec_ -eq 1 || die
35 test_expect_success
'no added lines for two empty files' '
37 printf "%s" "" >expected &&
38 diff_strings "" "" | diff_added_lines >actual &&
39 test_diff expected actual
42 test_expect_success
'one line added to empty file' '
44 printf "%s\n" "newline" >expected &&
45 diff_strings "" "newline
46 " | diff_added_lines >actual &&
47 test_diff expected actual
50 test_expect_success
'one line w/o nl added to empty file' '
52 printf "%s\n" "newline" >expected &&
53 diff_strings "" "newline" | diff_added_lines >actual &&
54 test_diff expected actual
57 test_expect_success
'two lines added to empty file' '
59 printf "%s\n" "line1" "line2" >expected &&
60 diff_strings "" "line1
62 " | diff_added_lines >actual &&
63 test_diff expected actual
66 test_expect_success
'two lines w/o final nl added to empty file' '
68 printf "%s\n" "line1" "line2" >expected &&
69 diff_strings "" "line1
70 line2" | diff_added_lines >actual &&
71 test_diff expected actual
74 test_expect_success
'one line prepended to one line file' '
76 printf "%s\n" "newline" >expected &&
82 " | diff_added_lines >actual &&
83 test_diff expected actual
86 test_expect_success
'one line appended to one line file' '
88 printf "%s\n" "newline" >expected &&
94 " | diff_added_lines >actual &&
95 test_diff expected actual
98 test_expect_success
'one line appended w/o nl to one line file' '
100 printf "%s\n" "newline" >expected &&
105 newline" | diff_added_lines >actual &&
106 test_diff expected actual
109 test_expect_success
'one line prepended and appended to one line file' '
111 printf "%s\n" "newline1" "newline2" >expected &&
118 " | diff_added_lines >actual &&
119 test_diff expected actual
122 test_expect_success
'one line prepended and appended w/o nl to one line file' '
124 printf "%s\n" "newline1" "newline2" >expected &&
130 newline2" | diff_added_lines >actual &&
131 test_diff expected actual
134 test_expect_success
'one line prepended to one line w/o nl file' '
136 printf "%s\n" "newline" >expected &&
140 original" | diff_added_lines >actual &&
141 test_diff expected actual
144 test_expect_success
'one line appended to one line w/o nl file' '
146 # the original shows up as a "+" because it got a nl added after it
147 printf "%s\n" "original" "newline" >expected &&
152 " | diff_added_lines >actual &&
153 test_diff expected actual
156 test_expect_success
'one line appended to one line w/o nl file w/ opt' '
158 printf "%s\n" "newline" >expected &&
163 " 1 | diff_added_lines >actual &&
164 test_diff expected actual
167 test_expect_success
'one line appended w/o nl to one line w/o nl file' '
169 # the original shows up as a "+" because it got a nl added after it
170 printf "%s\n" "original" "newline" >expected &&
174 newline" | diff_added_lines >actual &&
175 test_diff expected actual
178 test_expect_success
'one line appended w/o nl to one line w/o nl file w/ opt' '
180 printf "%s\n" "newline" >expected &&
184 newline" 1 | diff_added_lines >actual &&
185 test_diff expected actual
188 test_expect_success
'one line prepended and appended to one line w/o nl file' '
190 # the original shows up as a "+" because it got a nl added after it
191 printf "%s\n" "newline1" "original" "newline2" >expected &&
197 " | diff_added_lines >actual &&
198 test_diff expected actual
201 test_expect_success
'one line prepended and appended to one line w/o nl file w/ opt' '
203 printf "%s\n" "newline1" "newline2" >expected &&
209 " 1 | diff_added_lines >actual &&
210 test_diff expected actual
213 test_expect_success
'one line prepended and appended w/o nl to one line w/o nl file' '
215 # the original shows up as a "+" because it got a nl added after it
216 printf "%s\n" "newline1" "original" "newline2" >expected &&
221 newline2" | diff_added_lines >actual &&
222 test_diff expected actual
225 test_expect_success
'one line prepended and appended w/o nl to one line w/o nl file w/ opt' '
227 printf "%s\n" "newline1" "newline2" >expected &&
232 newline2" 1 | diff_added_lines >actual &&
233 test_diff expected actual