From 857e25c31f6d5e3c0994ff75c85c78e4600c1b69 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:01:17 -1000 Subject: Check each side's line numbers in a later hunk The test for a hunk that carries a length ran on foo's diff, whose only numbered side is +1 with no length, so it repeated the comma-less test. Every fixture hunk started at line 1, so a parser that always answered 1 passed. A line 0 never gets a link, so the absent 0 link could not show either way. --- tests/t0107-diff.sh | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/tests/t0107-diff.sh b/tests/t0107-diff.sh index 3c1f09c..b779890 100755 --- a/tests/t0107-diff.sh +++ b/tests/t0107-diff.sh @@ -58,14 +58,39 @@ test_expect_success 'set up a repo with single-line hunks' ' ' test_expect_success 'ssdiff numbers a comma-less hunk from its real line' ' - cgit_rc hunk1rc "url=hunk1/diff/&dt=1" >tmp && - grep "#n1.>1" tmp && - ! grep "#n0.>0" tmp + old=$(git -C repos/hunk1 rev-parse HEAD~1) && + new=$(git -C repos/hunk1 rev-parse HEAD) && + cgit_ok hunk1rc "url=hunk1/diff/&dt=1" >tmp && + grep "1" tmp && + grep "1" tmp ' -test_expect_success 'ssdiff still numbers a hunk that carries a length' ' - cgit_url "foo/diff&dt=1" >tmp && - grep "#n1.>1" tmp +# A line dropped near the top leaves the two sides of the later hunk starting +# at different lines, so each side has to be numbered from its own half of the +# header. +test_expect_success 'set up a repo whose later hunk starts apart on each side' ' + mkrepo repos/later 1 && + ( + cd repos/later && + test_seq 1 20 >twenty.txt && + git add twenty.txt && + git commit -m "add twenty.txt" && + test_seq 1 20 | sed -e 2d -e s/^15$/fifteen/ >twenty.txt && + git commit -am "change twenty.txt" + ) && + cgitrc_repo laterrc later && + git -C repos/later diff HEAD~1 HEAD >raw.diff && + grep "^@@ -12,7 +11,7 @@" raw.diff +' + +test_expect_success 'ssdiff numbers each side of a hunk from its own start' ' + old=$(git -C repos/later rev-parse HEAD~1) && + new=$(git -C repos/later rev-parse HEAD) && + cgit_ok laterrc "url=later/diff/&dt=1" >tmp && + grep -x "1212" tmp && + grep -x "1112" tmp && + grep "15" tmp && + grep "14" tmp ' # The character level highlight reuses one table across every changed pair, so -- cgit 2.12.1