33test_description=' basic tests for the SHA1 array implementation'
44. ./test-lib.sh
55
6- echo20 () {
6+ echoid () {
77 prefix=" ${1: +$1 } "
88 shift
99 while test $# -gt 0
1010 do
11- echo " $prefix $1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1 "
11+ echo " $prefix$ZERO_OID " | sed -e " s/00/ $1 /g "
1212 shift
1313 done
1414}
1515
1616test_expect_success ' ordered enumeration' '
17- echo20 "" 44 55 88 aa >expect &&
17+ echoid "" 44 55 88 aa >expect &&
1818 {
19- echo20 append 88 44 aa 55 &&
19+ echoid append 88 44 aa 55 &&
2020 echo for_each_unique
2121 } | test-tool sha1-array >actual &&
2222 test_cmp expect actual
2323'
2424
2525test_expect_success ' ordered enumeration with duplicate suppression' '
26- echo20 "" 44 55 88 aa >expect &&
26+ echoid "" 44 55 88 aa >expect &&
2727 {
28- echo20 append 88 44 aa 55 &&
29- echo20 append 88 44 aa 55 &&
28+ echoid append 88 44 aa 55 &&
29+ echoid append 88 44 aa 55 &&
3030 echo for_each_unique
3131 } | test-tool sha1-array >actual &&
3232 test_cmp expect actual
3333'
3434
3535test_expect_success ' lookup' '
3636 {
37- echo20 append 88 44 aa 55 &&
38- echo20 lookup 55
37+ echoid append 88 44 aa 55 &&
38+ echoid lookup 55
3939 } | test-tool sha1-array >actual &&
4040 n=$(cat actual) &&
4141 test "$n" -eq 1
4242'
4343
4444test_expect_success ' lookup non-existing entry' '
4545 {
46- echo20 append 88 44 aa 55 &&
47- echo20 lookup 33
46+ echoid append 88 44 aa 55 &&
47+ echoid lookup 33
4848 } | test-tool sha1-array >actual &&
4949 n=$(cat actual) &&
5050 test "$n" -lt 0
5151'
5252
5353test_expect_success ' lookup with duplicates' '
5454 {
55- echo20 append 88 44 aa 55 &&
56- echo20 append 88 44 aa 55 &&
57- echo20 lookup 55
55+ echoid append 88 44 aa 55 &&
56+ echoid append 88 44 aa 55 &&
57+ echoid lookup 55
5858 } | test-tool sha1-array >actual &&
5959 n=$(cat actual) &&
6060 test "$n" -ge 2 &&
@@ -63,28 +63,33 @@ test_expect_success 'lookup with duplicates' '
6363
6464test_expect_success ' lookup non-existing entry with duplicates' '
6565 {
66- echo20 append 88 44 aa 55 &&
67- echo20 append 88 44 aa 55 &&
68- echo20 lookup 66
66+ echoid append 88 44 aa 55 &&
67+ echoid append 88 44 aa 55 &&
68+ echoid lookup 66
6969 } | test-tool sha1-array >actual &&
7070 n=$(cat actual) &&
7171 test "$n" -lt 0
7272'
7373
7474test_expect_success ' lookup with almost duplicate values' '
75+ # n-1 5s
76+ root=$(echoid "" 55) &&
77+ root=${root%5} &&
7578 {
76- echo "append 5555555555555555555555555555555555555555" &&
77- echo "append 555555555555555555555555555555555555555f" &&
78- echo20 lookup 55
79+ id1="${root}5" &&
80+ id2="${root}f" &&
81+ echo "append $id1" &&
82+ echo "append $id2" &&
83+ echoid lookup 55
7984 } | test-tool sha1-array >actual &&
8085 n=$(cat actual) &&
8186 test "$n" -eq 0
8287'
8388
8489test_expect_success ' lookup with single duplicate value' '
8590 {
86- echo20 append 55 55 &&
87- echo20 lookup 55
91+ echoid append 55 55 &&
92+ echoid lookup 55
8893 } | test-tool sha1-array >actual &&
8994 n=$(cat actual) &&
9095 test "$n" -ge 0 &&
0 commit comments