2007-12-16 22:49:17 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='common tail optimization'
|
|
|
|
|
2021-10-31 00:24:19 +02:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2007-12-16 22:49:17 +01:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
z=zzzzzzzz ;# 8
|
|
|
|
z="$z$z$z$z$z$z$z$z" ;# 64
|
|
|
|
z="$z$z$z$z$z$z$z$z" ;# 512
|
|
|
|
z="$z$z$z$z" ;# 2048
|
|
|
|
z2047=$(expr "$z" : '.\(.*\)') ; #2047
|
|
|
|
|
2007-12-20 01:21:30 +01:00
|
|
|
x=zzzzzzzzzz ;# 10
|
|
|
|
y="$x$x$x$x$x$x$x$x$x$x" ;# 100
|
|
|
|
z="$y$y$y$y$y$y$y$y$y$y" ;# 1000
|
|
|
|
z1000=$z
|
|
|
|
z100=$y
|
|
|
|
z10=$x
|
2007-12-16 22:49:17 +01:00
|
|
|
|
2007-12-20 01:21:30 +01:00
|
|
|
zs() {
|
|
|
|
count="$1"
|
|
|
|
while test "$count" -ge 1000
|
|
|
|
do
|
|
|
|
count=$(($count - 1000))
|
|
|
|
printf "%s" $z1000
|
|
|
|
done
|
|
|
|
while test "$count" -ge 100
|
|
|
|
do
|
|
|
|
count=$(($count - 100))
|
|
|
|
printf "%s" $z100
|
|
|
|
done
|
|
|
|
while test "$count" -ge 10
|
|
|
|
do
|
|
|
|
count=$(($count - 10))
|
|
|
|
printf "%s" $z10
|
|
|
|
done
|
|
|
|
while test "$count" -ge 1
|
|
|
|
do
|
|
|
|
count=$(($count - 1))
|
|
|
|
printf "z"
|
|
|
|
done
|
|
|
|
}
|
2007-12-16 22:49:17 +01:00
|
|
|
|
2007-12-20 01:21:30 +01:00
|
|
|
zc () {
|
|
|
|
sed -e "/^index/d" \
|
|
|
|
-e "s/$z1000/Q/g" \
|
|
|
|
-e "s/QQQQQQQQQ/Z9000/g" \
|
|
|
|
-e "s/QQ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Z3/g" \
|
|
|
|
-e "s/QQ/Z2/g" \
|
|
|
|
-e "s/Q/Z1/g" \
|
|
|
|
-e "s/0Z//g" \
|
|
|
|
;
|
|
|
|
}
|
2007-12-16 22:49:17 +01:00
|
|
|
|
2007-12-20 01:21:30 +01:00
|
|
|
expect_pattern () {
|
|
|
|
cnt="$1"
|
|
|
|
cat <<EOF
|
|
|
|
diff --git a/file-a$cnt b/file-a$cnt
|
|
|
|
--- a/file-a$cnt
|
|
|
|
+++ b/file-a$cnt
|
2007-12-16 22:49:17 +01:00
|
|
|
@@ -1 +1 @@
|
2007-12-20 01:21:30 +01:00
|
|
|
-Z${cnt}a
|
|
|
|
+Z${cnt}A
|
|
|
|
diff --git a/file-b$cnt b/file-b$cnt
|
|
|
|
--- a/file-b$cnt
|
|
|
|
+++ b/file-b$cnt
|
2007-12-16 22:49:17 +01:00
|
|
|
@@ -1 +1 @@
|
|
|
|
-b
|
|
|
|
+B
|
2007-12-20 01:21:30 +01:00
|
|
|
diff --git a/file-c$cnt b/file-c$cnt
|
|
|
|
--- a/file-c$cnt
|
|
|
|
+++ b/file-c$cnt
|
2007-12-16 22:49:17 +01:00
|
|
|
@@ -1 +1 @@
|
2007-12-20 01:21:30 +01:00
|
|
|
-cZ$cnt
|
2007-12-16 22:49:17 +01:00
|
|
|
\ No newline at end of file
|
2007-12-20 01:21:30 +01:00
|
|
|
+CZ$cnt
|
2007-12-16 22:49:17 +01:00
|
|
|
\ No newline at end of file
|
2007-12-20 01:21:30 +01:00
|
|
|
diff --git a/file-d$cnt b/file-d$cnt
|
|
|
|
--- a/file-d$cnt
|
|
|
|
+++ b/file-d$cnt
|
2007-12-16 22:49:17 +01:00
|
|
|
@@ -1 +1 @@
|
|
|
|
-d
|
|
|
|
+D
|
|
|
|
EOF
|
2007-12-20 01:21:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sample='1023 1024 1025 2047 4095'
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
for n in $sample
|
|
|
|
do
|
2018-07-02 02:24:00 +02:00
|
|
|
( zs $n && echo a ) >file-a$n &&
|
|
|
|
( echo b && zs $n && echo ) >file-b$n &&
|
|
|
|
( printf c && zs $n ) >file-c$n &&
|
|
|
|
( echo d && zs $n ) >file-d$n &&
|
2007-12-20 01:21:30 +01:00
|
|
|
|
|
|
|
git add file-a$n file-b$n file-c$n file-d$n &&
|
|
|
|
|
2018-07-02 02:24:00 +02:00
|
|
|
( zs $n && echo A ) >file-a$n &&
|
|
|
|
( echo B && zs $n && echo ) >file-b$n &&
|
|
|
|
( printf C && zs $n ) >file-c$n &&
|
|
|
|
( echo D && zs $n ) >file-d$n &&
|
2007-12-20 01:21:30 +01:00
|
|
|
|
2015-03-25 06:29:52 +01:00
|
|
|
expect_pattern $n || return 1
|
2007-12-20 01:21:30 +01:00
|
|
|
|
|
|
|
done >expect
|
|
|
|
'
|
2007-12-16 22:49:17 +01:00
|
|
|
|
|
|
|
test_expect_success 'diff -U0' '
|
|
|
|
|
2007-12-20 01:21:30 +01:00
|
|
|
for n in $sample
|
|
|
|
do
|
2021-12-09 06:11:13 +01:00
|
|
|
git diff -U0 file-?$n || return 1
|
2007-12-20 01:21:30 +01:00
|
|
|
done | zc >actual &&
|
2008-03-12 22:36:36 +01:00
|
|
|
test_cmp expect actual
|
2007-12-16 22:49:17 +01:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|