Merge branch 'rs/diff-parseopts-cleanup'
[git/gitster.git] / t / t4024-diff-optimize-common.sh
blobe2f0eca4af065071a3ea5096e259212557aa4491
1 #!/bin/sh
3 test_description='common tail optimization'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 z=zzzzzzzz ;# 8
9 z="$z$z$z$z$z$z$z$z" ;# 64
10 z="$z$z$z$z$z$z$z$z" ;# 512
11 z="$z$z$z$z" ;# 2048
12 z2047=$(expr "$z" : '.\(.*\)') ; #2047
14 x=zzzzzzzzzz ;# 10
15 y="$x$x$x$x$x$x$x$x$x$x" ;# 100
16 z="$y$y$y$y$y$y$y$y$y$y" ;# 1000
17 z1000=$z
18 z100=$y
19 z10=$x
21 zs() {
22 count="$1"
23 while test "$count" -ge 1000
25 count=$(($count - 1000))
26 printf "%s" $z1000
27 done
28 while test "$count" -ge 100
30 count=$(($count - 100))
31 printf "%s" $z100
32 done
33 while test "$count" -ge 10
35 count=$(($count - 10))
36 printf "%s" $z10
37 done
38 while test "$count" -ge 1
40 count=$(($count - 1))
41 printf "z"
42 done
45 zc () {
46 sed -e "/^index/d" \
47 -e "s/$z1000/Q/g" \
48 -e "s/QQQQQQQQQ/Z9000/g" \
49 -e "s/QQQQQQQQ/Z8000/g" \
50 -e "s/QQQQQQQ/Z7000/g" \
51 -e "s/QQQQQQ/Z6000/g" \
52 -e "s/QQQQQ/Z5000/g" \
53 -e "s/QQQQ/Z4000/g" \
54 -e "s/QQQ/Z3000/g" \
55 -e "s/QQ/Z2000/g" \
56 -e "s/Q/Z1000/g" \
57 -e "s/$z100/Q/g" \
58 -e "s/QQQQQQQQQ/Z900/g" \
59 -e "s/QQQQQQQQ/Z800/g" \
60 -e "s/QQQQQQQ/Z700/g" \
61 -e "s/QQQQQQ/Z600/g" \
62 -e "s/QQQQQ/Z500/g" \
63 -e "s/QQQQ/Z400/g" \
64 -e "s/QQQ/Z300/g" \
65 -e "s/QQ/Z200/g" \
66 -e "s/Q/Z100/g" \
67 -e "s/000Z//g" \
68 -e "s/$z10/Q/g" \
69 -e "s/QQQQQQQQQ/Z90/g" \
70 -e "s/QQQQQQQQ/Z80/g" \
71 -e "s/QQQQQQQ/Z70/g" \
72 -e "s/QQQQQQ/Z60/g" \
73 -e "s/QQQQQ/Z50/g" \
74 -e "s/QQQQ/Z40/g" \
75 -e "s/QQQ/Z30/g" \
76 -e "s/QQ/Z20/g" \
77 -e "s/Q/Z10/g" \
78 -e "s/00Z//g" \
79 -e "s/z/Q/g" \
80 -e "s/QQQQQQQQQ/Z9/g" \
81 -e "s/QQQQQQQQ/Z8/g" \
82 -e "s/QQQQQQQ/Z7/g" \
83 -e "s/QQQQQQ/Z6/g" \
84 -e "s/QQQQQ/Z5/g" \
85 -e "s/QQQQ/Z4/g" \
86 -e "s/QQQ/Z3/g" \
87 -e "s/QQ/Z2/g" \
88 -e "s/Q/Z1/g" \
89 -e "s/0Z//g" \
93 expect_pattern () {
94 cnt="$1"
95 cat <<EOF
96 diff --git a/file-a$cnt b/file-a$cnt
97 --- a/file-a$cnt
98 +++ b/file-a$cnt
99 @@ -1 +1 @@
100 -Z${cnt}a
101 +Z${cnt}A
102 diff --git a/file-b$cnt b/file-b$cnt
103 --- a/file-b$cnt
104 +++ b/file-b$cnt
105 @@ -1 +1 @@
108 diff --git a/file-c$cnt b/file-c$cnt
109 --- a/file-c$cnt
110 +++ b/file-c$cnt
111 @@ -1 +1 @@
112 -cZ$cnt
113 \ No newline at end of file
114 +CZ$cnt
115 \ No newline at end of file
116 diff --git a/file-d$cnt b/file-d$cnt
117 --- a/file-d$cnt
118 +++ b/file-d$cnt
119 @@ -1 +1 @@
125 sample='1023 1024 1025 2047 4095'
127 test_expect_success setup '
129 for n in $sample
131 ( zs $n && echo a ) >file-a$n &&
132 ( echo b && zs $n && echo ) >file-b$n &&
133 ( printf c && zs $n ) >file-c$n &&
134 ( echo d && zs $n ) >file-d$n &&
136 git add file-a$n file-b$n file-c$n file-d$n &&
138 ( zs $n && echo A ) >file-a$n &&
139 ( echo B && zs $n && echo ) >file-b$n &&
140 ( printf C && zs $n ) >file-c$n &&
141 ( echo D && zs $n ) >file-d$n &&
143 expect_pattern $n || return 1
145 done >expect
148 test_expect_success 'diff -U0' '
150 for n in $sample
152 git diff -U0 file-?$n || return 1
153 done | zc >actual &&
154 test_cmp expect actual
158 test_done