#!/bin/sh test_description='Check content on diff page' . ./setup.sh test_expect_success 'generate foo/diff' 'cgit_url "foo/diff" >tmp' test_expect_success 'find diff header' 'grep "a/file-5 b/file-5" tmp' test_expect_success 'find blob link' 'grep "@@ -0,0 +1 @@" tmp ' test_expect_success 'find added line' ' grep "
+5
" tmp ' # --- Side-by-side line numbers for a hunk that covers a single line --------- # git writes the length only when a hunk spans more than one line, so a header # reads "@@ -1 +1 @@". Requiring a comma after the number left those hunks # numbered from zero, which dropped the line-number link entirely. test_expect_success 'set up a repo with single-line hunks' ' mkrepo repos/hunk1 1 && ( cd repos/hunk1 && printf "only\n" >one.txt && git add one.txt && git commit -m "add one.txt" && printf "ONLY\n" >one.txt && git commit -am "change one.txt" ) && { echo "virtual-root=/" && echo "cache-size=0" && echo "repo.url=hunk1" && echo "repo.path=$PWD/repos/hunk1/.git" } >hunk1rc && git -C repos/hunk1 diff HEAD~1 HEAD >raw.diff && grep "^@@ -1 +1 @@" raw.diff ' test_expect_success 'ssdiff numbers a comma-less hunk from its real line' ' CGIT_CONFIG="$PWD/hunk1rc" QUERY_STRING="url=hunk1/diff/&dt=1" cgit >tmp && grep "#n1.>1
" tmp && ! grep "#n0.>0" tmp ' test_expect_success 'ssdiff still numbers a hunk that carries a length' ' cgit_query "url=foo/diff&dt=1" >tmp && grep "#n1.>1" tmp ' # --- Intra-line highlighting across many changed pairs ---------------------- # The character-level highlight reuses one table across every changed pair. # Lines shrink down the file so a short comparison always follows a longer one, # which is where a stale cell would show up as misplaced del and add spans. test_expect_success 'set up a repo with shrinking changed lines' ' mkrepo repos/lcs 1 && ( cd repos/lcs && awk "BEGIN{for(n=120;n>0;n-=3){s=\"\"; for(i=0;ilines.txt && git add lines.txt && git commit -m "add lines.txt" && awk "BEGIN{for(n=120;n>0;n-=3){s=\"\"; for(i=0;ilines.txt && git commit -am "change every line" ) && { echo "virtual-root=/" && echo "cache-size=0" && echo "repo.url=lcs" && echo "repo.path=$PWD/repos/lcs/.git" } >lcsrc ' test_expect_success 'every changed pair gets both a del and an add span' ' CGIT_CONFIG="$PWD/lcsrc" QUERY_STRING="url=lcs/diff/&dt=1" cgit >tmp && dels=$(grep -o "" tmp | wc -l) && adds=$(grep -o "" tmp | wc -l) && test "$dels" -gt 0 && test "$dels" -eq "$adds" ' test_expect_success 'stripping the highlight leaves every line intact' ' sed -e "s/<[^>]*>//g" tmp >plain.out && git -C repos/lcs show HEAD~1:lines.txt >old.txt && git -C repos/lcs show HEAD:lines.txt >new.txt && while read -r line do grep -qF "$line" plain.out || { echo "missing old line: $line" return 1 } done