sequencer: detect author name errors in read_author_script()
[git/debian.git] / t / t0011-hashmap.sh
blob1cb6aa6824321656264e427f299899acf0754357
1 #!/bin/sh
3 test_description='test hashmap and string hash functions'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_hashmap() {
9 echo "$1" | test-tool hashmap $3 > actual &&
10 echo "$2" > expect &&
11 test_cmp expect actual
14 test_expect_success 'put' '
16 test_hashmap "put key1 value1
17 put key2 value2
18 put fooBarFrotz value3
19 put foobarfrotz value4
20 size" "NULL
21 NULL
22 NULL
23 NULL
24 64 4"
28 test_expect_success 'put (case insensitive)' '
30 test_hashmap "put key1 value1
31 put key2 value2
32 put fooBarFrotz value3
33 size" "NULL
34 NULL
35 NULL
36 64 3" ignorecase
40 test_expect_success 'replace' '
42 test_hashmap "put key1 value1
43 put key1 value2
44 put fooBarFrotz value3
45 put fooBarFrotz value4
46 size" "NULL
47 value1
48 NULL
49 value3
50 64 2"
54 test_expect_success 'replace (case insensitive)' '
56 test_hashmap "put key1 value1
57 put Key1 value2
58 put fooBarFrotz value3
59 put foobarfrotz value4
60 size" "NULL
61 value1
62 NULL
63 value3
64 64 2" ignorecase
68 test_expect_success 'get' '
70 test_hashmap "put key1 value1
71 put key2 value2
72 put fooBarFrotz value3
73 put foobarfrotz value4
74 get key1
75 get key2
76 get fooBarFrotz
77 get notInMap" "NULL
78 NULL
79 NULL
80 NULL
81 value1
82 value2
83 value3
84 NULL"
88 test_expect_success 'get (case insensitive)' '
90 test_hashmap "put key1 value1
91 put key2 value2
92 put fooBarFrotz value3
93 get Key1
94 get keY2
95 get foobarfrotz
96 get notInMap" "NULL
97 NULL
98 NULL
99 value1
100 value2
101 value3
102 NULL" ignorecase
106 test_expect_success 'add' '
108 test_hashmap "add key1 value1
109 add key1 value2
110 add fooBarFrotz value3
111 add fooBarFrotz value4
112 get key1
113 get fooBarFrotz
114 get notInMap" "value2
115 value1
116 value4
117 value3
118 NULL"
122 test_expect_success 'add (case insensitive)' '
124 test_hashmap "add key1 value1
125 add Key1 value2
126 add fooBarFrotz value3
127 add foobarfrotz value4
128 get key1
129 get Foobarfrotz
130 get notInMap" "value2
131 value1
132 value4
133 value3
134 NULL" ignorecase
138 test_expect_success 'remove' '
140 test_hashmap "put key1 value1
141 put key2 value2
142 put fooBarFrotz value3
143 remove key1
144 remove key2
145 remove notInMap
146 size" "NULL
147 NULL
148 NULL
149 value1
150 value2
151 NULL
152 64 1"
156 test_expect_success 'remove (case insensitive)' '
158 test_hashmap "put key1 value1
159 put key2 value2
160 put fooBarFrotz value3
161 remove Key1
162 remove keY2
163 remove notInMap
164 size" "NULL
165 NULL
166 NULL
167 value1
168 value2
169 NULL
170 64 1" ignorecase
174 test_expect_success 'iterate' '
175 test-tool hashmap >actual.raw <<-\EOF &&
176 put key1 value1
177 put key2 value2
178 put fooBarFrotz value3
179 iterate
182 cat >expect <<-\EOF &&
183 NULL
184 NULL
185 NULL
186 fooBarFrotz value3
187 key1 value1
188 key2 value2
191 sort <actual.raw >actual &&
192 test_cmp expect actual
195 test_expect_success 'iterate (case insensitive)' '
196 test-tool hashmap ignorecase >actual.raw <<-\EOF &&
197 put key1 value1
198 put key2 value2
199 put fooBarFrotz value3
200 iterate
203 cat >expect <<-\EOF &&
204 NULL
205 NULL
206 NULL
207 fooBarFrotz value3
208 key1 value1
209 key2 value2
212 sort <actual.raw >actual &&
213 test_cmp expect actual
216 test_expect_success 'grow / shrink' '
218 rm -f in &&
219 rm -f expect &&
220 for n in $(test_seq 51)
222 echo put key$n value$n >> in &&
223 echo NULL >> expect || return 1
224 done &&
225 echo size >> in &&
226 echo 64 51 >> expect &&
227 echo put key52 value52 >> in &&
228 echo NULL >> expect &&
229 echo size >> in &&
230 echo 256 52 >> expect &&
231 for n in $(test_seq 12)
233 echo remove key$n >> in &&
234 echo value$n >> expect || return 1
235 done &&
236 echo size >> in &&
237 echo 256 40 >> expect &&
238 echo remove key40 >> in &&
239 echo value40 >> expect &&
240 echo size >> in &&
241 echo 64 39 >> expect &&
242 cat in | test-tool hashmap > out &&
243 test_cmp expect out
247 test_expect_success 'string interning' '
249 test_hashmap "intern value1
250 intern Value1
251 intern value2
252 intern value2
253 " "value1
254 Value1
255 value2
256 value2"
260 test_done