ci: skip GitHub workflow runs for already-tested commits/trees
[git.git] / t / t0011-hashmap.sh
blob5343ffd3f92c1637bb60719d812a01e0ab6d4064
1 #!/bin/sh
3 test_description='test hashmap and string hash functions'
4 . ./test-lib.sh
6 test_hashmap() {
7 echo "$1" | test-tool hashmap $3 > actual &&
8 echo "$2" > expect &&
9 test_cmp expect actual
12 test_expect_success 'put' '
14 test_hashmap "put key1 value1
15 put key2 value2
16 put fooBarFrotz value3
17 put foobarfrotz value4
18 size" "NULL
19 NULL
20 NULL
21 NULL
22 64 4"
26 test_expect_success 'put (case insensitive)' '
28 test_hashmap "put key1 value1
29 put key2 value2
30 put fooBarFrotz value3
31 size" "NULL
32 NULL
33 NULL
34 64 3" ignorecase
38 test_expect_success 'replace' '
40 test_hashmap "put key1 value1
41 put key1 value2
42 put fooBarFrotz value3
43 put fooBarFrotz value4
44 size" "NULL
45 value1
46 NULL
47 value3
48 64 2"
52 test_expect_success 'replace (case insensitive)' '
54 test_hashmap "put key1 value1
55 put Key1 value2
56 put fooBarFrotz value3
57 put foobarfrotz value4
58 size" "NULL
59 value1
60 NULL
61 value3
62 64 2" ignorecase
66 test_expect_success 'get' '
68 test_hashmap "put key1 value1
69 put key2 value2
70 put fooBarFrotz value3
71 put foobarfrotz value4
72 get key1
73 get key2
74 get fooBarFrotz
75 get notInMap" "NULL
76 NULL
77 NULL
78 NULL
79 value1
80 value2
81 value3
82 NULL"
86 test_expect_success 'get (case insensitive)' '
88 test_hashmap "put key1 value1
89 put key2 value2
90 put fooBarFrotz value3
91 get Key1
92 get keY2
93 get foobarfrotz
94 get notInMap" "NULL
95 NULL
96 NULL
97 value1
98 value2
99 value3
100 NULL" ignorecase
104 test_expect_success 'add' '
106 test_hashmap "add key1 value1
107 add key1 value2
108 add fooBarFrotz value3
109 add fooBarFrotz value4
110 get key1
111 get fooBarFrotz
112 get notInMap" "value2
113 value1
114 value4
115 value3
116 NULL"
120 test_expect_success 'add (case insensitive)' '
122 test_hashmap "add key1 value1
123 add Key1 value2
124 add fooBarFrotz value3
125 add foobarfrotz value4
126 get key1
127 get Foobarfrotz
128 get notInMap" "value2
129 value1
130 value4
131 value3
132 NULL" ignorecase
136 test_expect_success 'remove' '
138 test_hashmap "put key1 value1
139 put key2 value2
140 put fooBarFrotz value3
141 remove key1
142 remove key2
143 remove notInMap
144 size" "NULL
145 NULL
146 NULL
147 value1
148 value2
149 NULL
150 64 1"
154 test_expect_success 'remove (case insensitive)' '
156 test_hashmap "put key1 value1
157 put key2 value2
158 put fooBarFrotz value3
159 remove Key1
160 remove keY2
161 remove notInMap
162 size" "NULL
163 NULL
164 NULL
165 value1
166 value2
167 NULL
168 64 1" ignorecase
172 test_expect_success 'iterate' '
173 test-tool hashmap >actual.raw <<-\EOF &&
174 put key1 value1
175 put key2 value2
176 put fooBarFrotz value3
177 iterate
180 cat >expect <<-\EOF &&
181 NULL
182 NULL
183 NULL
184 fooBarFrotz value3
185 key1 value1
186 key2 value2
189 sort <actual.raw >actual &&
190 test_cmp expect actual
193 test_expect_success 'iterate (case insensitive)' '
194 test-tool hashmap ignorecase >actual.raw <<-\EOF &&
195 put key1 value1
196 put key2 value2
197 put fooBarFrotz value3
198 iterate
201 cat >expect <<-\EOF &&
202 NULL
203 NULL
204 NULL
205 fooBarFrotz value3
206 key1 value1
207 key2 value2
210 sort <actual.raw >actual &&
211 test_cmp expect actual
214 test_expect_success 'grow / shrink' '
216 rm -f in &&
217 rm -f expect &&
218 for n in $(test_seq 51)
220 echo put key$n value$n >> in &&
221 echo NULL >> expect
222 done &&
223 echo size >> in &&
224 echo 64 51 >> expect &&
225 echo put key52 value52 >> in &&
226 echo NULL >> expect &&
227 echo size >> in &&
228 echo 256 52 >> expect &&
229 for n in $(test_seq 12)
231 echo remove key$n >> in &&
232 echo value$n >> expect
233 done &&
234 echo size >> in &&
235 echo 256 40 >> expect &&
236 echo remove key40 >> in &&
237 echo value40 >> expect &&
238 echo size >> in &&
239 echo 64 39 >> expect &&
240 cat in | test-tool hashmap > out &&
241 test_cmp expect out
245 test_expect_success 'string interning' '
247 test_hashmap "intern value1
248 intern Value1
249 intern value2
250 intern value2
251 " "value1
252 Value1
253 value2
254 value2"
258 test_done