git-prompt: use here-doc instead of here-string
[git/gitster.git] / t / t0064-oid-array.sh
blobde74b692d0cfc54eb694f3407f810c852cf200e8
1 #!/bin/sh
3 test_description='basic tests for the oid array implementation'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 echoid () {
9 prefix="${1:+$1 }"
10 shift
11 while test $# -gt 0
13 echo "$prefix$ZERO_OID" | sed -e "s/00/$1/g"
14 shift
15 done
18 test_expect_success 'without repository' '
19 cat >expect <<-EOF &&
20 4444444444444444444444444444444444444444
21 5555555555555555555555555555555555555555
22 8888888888888888888888888888888888888888
23 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
24 EOF
25 cat >input <<-EOF &&
26 append 4444444444444444444444444444444444444444
27 append 5555555555555555555555555555555555555555
28 append 8888888888888888888888888888888888888888
29 append aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
30 for_each_unique
31 EOF
32 nongit test-tool oid-array <input >actual &&
33 test_cmp expect actual
36 test_expect_success 'ordered enumeration' '
37 echoid "" 44 55 88 aa >expect &&
39 echoid append 88 44 aa 55 &&
40 echo for_each_unique
41 } | test-tool oid-array >actual &&
42 test_cmp expect actual
45 test_expect_success 'ordered enumeration with duplicate suppression' '
46 echoid "" 44 55 88 aa >expect &&
48 echoid append 88 44 aa 55 &&
49 echoid append 88 44 aa 55 &&
50 echoid append 88 44 aa 55 &&
51 echo for_each_unique
52 } | test-tool oid-array >actual &&
53 test_cmp expect actual
56 test_expect_success 'lookup' '
58 echoid append 88 44 aa 55 &&
59 echoid lookup 55
60 } | test-tool oid-array >actual &&
61 n=$(cat actual) &&
62 test "$n" -eq 1
65 test_expect_success 'lookup non-existing entry' '
67 echoid append 88 44 aa 55 &&
68 echoid lookup 33
69 } | test-tool oid-array >actual &&
70 n=$(cat actual) &&
71 test "$n" -lt 0
74 test_expect_success 'lookup with duplicates' '
76 echoid append 88 44 aa 55 &&
77 echoid append 88 44 aa 55 &&
78 echoid append 88 44 aa 55 &&
79 echoid lookup 55
80 } | test-tool oid-array >actual &&
81 n=$(cat actual) &&
82 test "$n" -ge 3 &&
83 test "$n" -le 5
86 test_expect_success 'lookup non-existing entry with duplicates' '
88 echoid append 88 44 aa 55 &&
89 echoid append 88 44 aa 55 &&
90 echoid append 88 44 aa 55 &&
91 echoid lookup 66
92 } | test-tool oid-array >actual &&
93 n=$(cat actual) &&
94 test "$n" -lt 0
97 test_expect_success 'lookup with almost duplicate values' '
98 # n-1 5s
99 root=$(echoid "" 55) &&
100 root=${root%5} &&
102 id1="${root}5" &&
103 id2="${root}f" &&
104 echo "append $id1" &&
105 echo "append $id2" &&
106 echoid lookup 55
107 } | test-tool oid-array >actual &&
108 n=$(cat actual) &&
109 test "$n" -eq 0
112 test_expect_success 'lookup with single duplicate value' '
114 echoid append 55 55 &&
115 echoid lookup 55
116 } | test-tool oid-array >actual &&
117 n=$(cat actual) &&
118 test "$n" -ge 0 &&
119 test "$n" -le 1
122 test_done