summary refs log tree commit diff
path: root/Test/V11db_gdbm.ztst
blob: 1d80f28f8177e26a19ac9df8162f0a3b550d48be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# Tests for the zsh/param/private module

%prep

 modname="zsh/db/gdbm"
 dbfile=db.gdbm
 if ! zmodload $modname 2>/dev/null; then
   ZTST_unimplemented="can't load $modname module for testing"
 fi
 rm -f db.gdbm

%test

 (zmodload -u $modname && zmodload $modname)
0:unload and reload the module without crashing

 ztie -d db/gdbm -f $dbfile dbase
 zuntie dbase
0:create the database

 ztie -r -d db/gdbm -f $dbfile dbase
 zuntie -u dbase
0:open the database read-only

 ztie -d db/gdbm -f $dbfile dbase
 dbase[testkey]=testdata
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 echo $dbase[testkey]
 zuntie -u dbase
0:store key in database
>testdata

 ztie -d db/gdbm -f $dbfile dbase2
 unset 'dbase2[testkey]'
 zuntie dbase2
 ztie -d db/gdbm -f $dbfile dbase
 echo $dbase[testkey]
 zuntie dbase
0:remove key from database (different variables)
>

 ztie -d db/gdbm -f $dbfile dbase
 dbase[testkey]=testdata
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 echo $dbase[testkey]
 zuntie -u dbase
 ztie -d db/gdbm -f $dbfile dbase
 unset 'dbase[testkey]'
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 echo $dbase[testkey]
 zuntie -u dbase
0:store & remove key from database (the same variables)
>testdata
>

 ztie -d db/gdbm -f $dbfile dbase
 dbase[testkey]=testdata
 dbase[testkey2]=$dbase[testkey]
 dbase[testkey3]=$dbase[testkey]x$dbase[testkey2]
 zuntie dbase
 ztie -d db/gdbm -f $dbfile dbase
 echo $dbase[testkey]
 echo $dbase[testkey2]
 echo $dbase[testkey3]
 zuntie dbase
0:store 2 keys fetching 1st
>testdata
>testdata
>testdataxtestdata

 ztie -d db/gdbm -f $dbfile dbase
 val=$dbase[testkey2]
 unset 'dbase[testkey2]'
 echo $val
 zuntie dbase
0:unset key that was fetched
>testdata

 ztie -r -d db/gdbm -f $dbfile dbase
 print -rl -- "${(kv)dbase[@]}"
 zuntie -u dbase
0:scan read-only tied hash
>testkey
>testdata
>testkey3
>testdataxtestdata

 ztie -d db/gdbm -f $dbfile dbase
 local -a arr
 arr=( "${(kv)dbase[@]}" )
 print -rl -- "${arr[@]}"
 zuntie dbase
0:different scan, also read-write mode
>testkey
>testdata
>testkey3
>testdataxtestdata

 ztie -d db/gdbm -f $dbfile dbase
 dbase=( a b c d )
 zuntie dbase
 ztie -d db/gdbm -f $dbfile dbase
 print -rl -- "${(kv)dbase[@]}"
 zuntie dbase
0:replace hash / database, scan
>c
>d
>a
>b

 ztie -d db/gdbm -f $dbfile dbase
 local -a arr
 arr=( "${dbase[@]}" )
 print -rl -- "${arr[@]}"
 zuntie dbase
0:scan with no (kv)
>d
>b

 ztie -d db/gdbm -f $dbfile dbase
 print -rl -- "${(k)dbase[@]}"
 zuntie dbase
0:scan with keys only (k)
>c
>a

 ztie -d db/gdbm -f $dbfile dbase
 print -rl -- "${(v)dbase[@]}"
 zuntie dbase
0:scan with keys only explicit (v)
>d
>b

 rm -f $dbfile
 ztie -r -d db/gdbm -f $dbfile dbase 2>/dev/null
1:read-only open non-existent database

 ztie -d db/gdbm -f $dbfile dbase
 dbase+=( a b )
 echo $dbase[a]
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 echo $dbase[a]
 print -rl -- "${(kv)dbase[@]}"
 zuntie -u dbase
 ztie -d db/gdbm -f $dbfile dbase
 dbase+=( c d )
 echo $dbase[a]
 echo $dbase[c]
 print -rl -- "${(kv)dbase[@]}"
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 echo $dbase[a]
 echo $dbase[c]
 print -rl -- "${(kv)dbase[@]}"
 zuntie -u dbase
0:Append with +=( ), also with existing data, also (kv) scan
>b
>b
>a
>b
>b
>d
>c
>d
>a
>b
>b
>d
>c
>d
>a
>b

 ztie -d db/gdbm -f $dbfile dbase
 echo ${(t)dbase}
 zuntie dbase
0:Type of tied parameter
>association-special

 typeset -ga dbase
 ztie -d db/gdbm -f $dbfile dbase
 echo ${(t)dbase}
 zuntie dbase
0:Type of tied parameter, with preceding unset
>association-special

 local -a dbase
 ztie -d db/gdbm -f $dbfile dbase
 echo ${(t)dbase}
 zuntie dbase
0:Type of tied parameter, with local parameter already existing
>association-local-special

 local -a dbase
 dbase=( fromarray )
 () {
     local -a dbase
     ztie -d db/gdbm -f $dbfile dbase
     echo ${(t)dbase}
     zuntie dbase
 }
 echo $dbase[1]
 ztie -d db/gdbm -f $dbfile dbase2
 echo "Can connect, so untie happened:" $dbase2[a]
 zuntie dbase2
0:Test of automatic untie (use of local scope) and of scoping
>association-local-special
>fromarray
>Can connect, so untie happened: b

 echo $zgdbm_tied ${#zgdbm_tied}
 ztie -r -d db/gdbm -f $dbfile dbase
 echo $zgdbm_tied ${#zgdbm_tied}
 ztie -d db/gdbm -f ${dbfile}2 dbase2
 echo $zgdbm_tied ${#zgdbm_tied}
 zuntie -u dbase
 echo $zgdbm_tied ${#zgdbm_tied}
 zuntie dbase2
 echo $zgdbm_tied ${#zgdbm_tied}
0:zgdbm_tied parameter
>0
>dbase 1
>dbase dbase2 2
>dbase2 1
>0

 unset zgdbm_tied 2>/dev/null
1:unset of read-only zgdbm_tied parameter

 ztie -d db/gdbm -f $dbfile dbase
 dbase[漢字]=漢字
 echo $dbase[漢字]
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 echo $dbase[漢字]
 zuntie -u dbase
0:Unicode test
>漢字
>漢字

 key="ab"$'\0'"ef"
 ztie -d db/gdbm -f $dbfile dbase
 dbase[$key]=value
 echo $dbase[$key]
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 echo $dbase[$key]
 zuntie -u dbase
 ztie -d db/gdbm -f $dbfile dbase
 dbase[$key]=$key
 zuntie dbase
 ztie -d db/gdbm -f $dbfile dbase
 [[ "$dbase[$key]" = "$key" ]] && echo correct
 zuntie dbase
0:Metafication of $'\0'
>value
>value
>correct

 ztie -d db/gdbm -f $dbfile dbase
 dbase=( 漢字 漢字 )
 echo $dbase[漢字]
 zuntie dbase
 ztie -d db/gdbm -f $dbfile dbase
 echo $dbase[漢字]
 zuntie dbase
 key="ab"$'\0'"ef"
 ztie -d db/gdbm -f $dbfile dbase
 dbase+=( $key $key )
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 [[ "$dbase[$key]" = "$key" ]] && echo correct
 zuntie -u dbase
0:Unicode & metafication test, different hash access
>漢字
>漢字
>correct

 ztie -d db/gdbm -f $dbfile dbase
 dbase=( 漢字 漢字 )
 zuntie dbase
 ztie -d db/gdbm -f $dbfile dbase
 noglob print -rl ${(kv)dbase[@]}
 zuntie dbase
0:Hash scanning and metafication
>漢字
>漢字

 ztie -d db/gdbm -f $dbfile dbase
 zgdbmpath dbase
 [[ $REPLY = */Test/db.gdbm ]] && echo correct
 zuntie dbase
 ztie -r -d db/gdbm -f $dbfile dbase
 zgdbmpath dbase
 [[ $REPLY = */Test/db.gdbm ]] && echo correct
 zuntie -u dbase
0:zgdbmpath builtin
>correct
>correct

%clean

  rm -f ${dbfile}*