]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0064-oid-array.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t0064-oid-array.sh
1 #!/bin/sh
2
3 test_description='basic tests for the oid array implementation'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 echoid () {
9 prefix="${1:+$1 }"
10 shift
11 while test $# -gt 0
12 do
13 echo "$prefix$ZERO_OID" | sed -e "s/00/$1/g"
14 shift
15 done
16 }
17
18 test_expect_success 'ordered enumeration' '
19 echoid "" 44 55 88 aa >expect &&
20 {
21 echoid append 88 44 aa 55 &&
22 echo for_each_unique
23 } | test-tool oid-array >actual &&
24 test_cmp expect actual
25 '
26
27 test_expect_success 'ordered enumeration with duplicate suppression' '
28 echoid "" 44 55 88 aa >expect &&
29 {
30 echoid append 88 44 aa 55 &&
31 echoid append 88 44 aa 55 &&
32 echoid append 88 44 aa 55 &&
33 echo for_each_unique
34 } | test-tool oid-array >actual &&
35 test_cmp expect actual
36 '
37
38 test_expect_success 'lookup' '
39 {
40 echoid append 88 44 aa 55 &&
41 echoid lookup 55
42 } | test-tool oid-array >actual &&
43 n=$(cat actual) &&
44 test "$n" -eq 1
45 '
46
47 test_expect_success 'lookup non-existing entry' '
48 {
49 echoid append 88 44 aa 55 &&
50 echoid lookup 33
51 } | test-tool oid-array >actual &&
52 n=$(cat actual) &&
53 test "$n" -lt 0
54 '
55
56 test_expect_success 'lookup with duplicates' '
57 {
58 echoid append 88 44 aa 55 &&
59 echoid append 88 44 aa 55 &&
60 echoid append 88 44 aa 55 &&
61 echoid lookup 55
62 } | test-tool oid-array >actual &&
63 n=$(cat actual) &&
64 test "$n" -ge 3 &&
65 test "$n" -le 5
66 '
67
68 test_expect_success 'lookup non-existing entry with duplicates' '
69 {
70 echoid append 88 44 aa 55 &&
71 echoid append 88 44 aa 55 &&
72 echoid append 88 44 aa 55 &&
73 echoid lookup 66
74 } | test-tool oid-array >actual &&
75 n=$(cat actual) &&
76 test "$n" -lt 0
77 '
78
79 test_expect_success 'lookup with almost duplicate values' '
80 # n-1 5s
81 root=$(echoid "" 55) &&
82 root=${root%5} &&
83 {
84 id1="${root}5" &&
85 id2="${root}f" &&
86 echo "append $id1" &&
87 echo "append $id2" &&
88 echoid lookup 55
89 } | test-tool oid-array >actual &&
90 n=$(cat actual) &&
91 test "$n" -eq 0
92 '
93
94 test_expect_success 'lookup with single duplicate value' '
95 {
96 echoid append 55 55 &&
97 echoid lookup 55
98 } | test-tool oid-array >actual &&
99 n=$(cat actual) &&
100 test "$n" -ge 0 &&
101 test "$n" -le 1
102 '
103
104 test_done