diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Emit generated runs in batches, not a write each
Diffstat (limited to 'tests')
-rwxr-xr-xtests/t0106-diff.sh53
1 file changed, 53 insertions, 0 deletions
diff --git a/tests/t0106-diff.sh b/tests/t0106-diff.sh
index 3e0d15c..4074276 100755
--- a/tests/t0106-diff.sh
+++ b/tests/t0106-diff.sh
@@ -51,4 +51,57 @@ test_expect_success 'ssdiff still numbers a hunk that carries a length' '
grep "#n1.>1</a>" 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;i<n;i++)s=s sprintf(\"%c\",97+(i*7+n)%26); print s}}" >lines.txt &&
+ git add lines.txt &&
+ git commit -m "add lines.txt" &&
+ awk "BEGIN{for(n=120;n>0;n-=3){s=\"\";
+ for(i=0;i<n;i++){c=97+(i*7+n)%26; if(i%7==0)c=97+(c-97+5)%26;
+ s=s sprintf(\"%c\",c)} print s}}" >lines.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 "<span class=.del.>" tmp | wc -l) &&
+ adds=$(grep -o "<span class=.add.>" 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 <old.txt &&
+ while read -r line
+ do
+ grep -qF "$line" plain.out || {
+ echo "missing new line: $line"
+ return 1
+ }
+ done <new.txt
+'
+
test_done