Merge branch 'me/fetch-into-shallow-safety' into maint
[git/mingw.git] / t / t0011-hashmap.sh
blob9c217d948c14dfd75f73e27a0911fd194eb11bce
1 #!/bin/sh
3 test_description='test hashmap and string hash functions'
4 . ./test-lib.sh
6 test_hashmap() {
7 echo "$1" | test-hashmap $3 > actual &&
8 echo "$2" > expect &&
9 test_cmp expect actual
12 test_expect_success 'hash functions' '
14 test_hashmap "hash key1" "2215982743 2215982743 116372151 116372151" &&
15 test_hashmap "hash key2" "2215982740 2215982740 116372148 116372148" &&
16 test_hashmap "hash fooBarFrotz" "1383912807 1383912807 3189766727 3189766727" &&
17 test_hashmap "hash foobarfrotz" "2862305959 2862305959 3189766727 3189766727"
21 test_expect_success 'put' '
23 test_hashmap "put key1 value1
24 put key2 value2
25 put fooBarFrotz value3
26 put foobarfrotz value4
27 size" "NULL
28 NULL
29 NULL
30 NULL
31 64 4"
35 test_expect_success 'put (case insensitive)' '
37 test_hashmap "put key1 value1
38 put key2 value2
39 put fooBarFrotz value3
40 size" "NULL
41 NULL
42 NULL
43 64 3" ignorecase
47 test_expect_success 'replace' '
49 test_hashmap "put key1 value1
50 put key1 value2
51 put fooBarFrotz value3
52 put fooBarFrotz value4
53 size" "NULL
54 value1
55 NULL
56 value3
57 64 2"
61 test_expect_success 'replace (case insensitive)' '
63 test_hashmap "put key1 value1
64 put Key1 value2
65 put fooBarFrotz value3
66 put foobarfrotz value4
67 size" "NULL
68 value1
69 NULL
70 value3
71 64 2" ignorecase
75 test_expect_success 'get' '
77 test_hashmap "put key1 value1
78 put key2 value2
79 put fooBarFrotz value3
80 put foobarfrotz value4
81 get key1
82 get key2
83 get fooBarFrotz
84 get notInMap" "NULL
85 NULL
86 NULL
87 NULL
88 value1
89 value2
90 value3
91 NULL"
95 test_expect_success 'get (case insensitive)' '
97 test_hashmap "put key1 value1
98 put key2 value2
99 put fooBarFrotz value3
100 get Key1
101 get keY2
102 get foobarfrotz
103 get notInMap" "NULL
104 NULL
105 NULL
106 value1
107 value2
108 value3
109 NULL" ignorecase
113 test_expect_success 'add' '
115 test_hashmap "add key1 value1
116 add key1 value2
117 add fooBarFrotz value3
118 add fooBarFrotz value4
119 get key1
120 get fooBarFrotz
121 get notInMap" "value2
122 value1
123 value4
124 value3
125 NULL"
129 test_expect_success 'add (case insensitive)' '
131 test_hashmap "add key1 value1
132 add Key1 value2
133 add fooBarFrotz value3
134 add foobarfrotz value4
135 get key1
136 get Foobarfrotz
137 get notInMap" "value2
138 value1
139 value4
140 value3
141 NULL" ignorecase
145 test_expect_success 'remove' '
147 test_hashmap "put key1 value1
148 put key2 value2
149 put fooBarFrotz value3
150 remove key1
151 remove key2
152 remove notInMap
153 size" "NULL
154 NULL
155 NULL
156 value1
157 value2
158 NULL
159 64 1"
163 test_expect_success 'remove (case insensitive)' '
165 test_hashmap "put key1 value1
166 put key2 value2
167 put fooBarFrotz value3
168 remove Key1
169 remove keY2
170 remove notInMap
171 size" "NULL
172 NULL
173 NULL
174 value1
175 value2
176 NULL
177 64 1" ignorecase
181 test_expect_success 'iterate' '
183 test_hashmap "put key1 value1
184 put key2 value2
185 put fooBarFrotz value3
186 iterate" "NULL
187 NULL
188 NULL
189 key2 value2
190 key1 value1
191 fooBarFrotz value3"
195 test_expect_success 'iterate (case insensitive)' '
197 test_hashmap "put key1 value1
198 put key2 value2
199 put fooBarFrotz value3
200 iterate" "NULL
201 NULL
202 NULL
203 fooBarFrotz value3
204 key2 value2
205 key1 value1" ignorecase
209 test_expect_success 'grow / shrink' '
211 rm -f in &&
212 rm -f expect &&
213 for n in $(test_seq 51)
215 echo put key$n value$n >> in &&
216 echo NULL >> expect
217 done &&
218 echo size >> in &&
219 echo 64 51 >> expect &&
220 echo put key52 value52 >> in &&
221 echo NULL >> expect &&
222 echo size >> in &&
223 echo 256 52 >> expect &&
224 for n in $(test_seq 12)
226 echo remove key$n >> in &&
227 echo value$n >> expect
228 done &&
229 echo size >> in &&
230 echo 256 40 >> expect &&
231 echo remove key40 >> in &&
232 echo value40 >> expect &&
233 echo size >> in &&
234 echo 64 39 >> expect &&
235 cat in | test-hashmap > out &&
236 test_cmp expect out
240 test_expect_success 'string interning' '
242 test_hashmap "intern value1
243 intern Value1
244 intern value2
245 intern value2
246 " "value1
247 Value1
248 value2
249 value2"
253 test_done