File: tie_array.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (301 lines) | stat: -rw-r--r-- 8,363 bytes parent folder | download | duplicates (7)
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
# Tests for the tie module.                              -*- tcl -*- 
#
# Copyright (c) 2004 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: tie_array.test,v 1.7 2006/10/09 21:41:42 andreas_kupries Exp $

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.4
testsNeedTcltest 1.0

support {
    use      snit/snit.tcl snit
    useLocal tie.tcl       tie
}
testing {
    useLocal tie_array.tcl tie::std::array
}

# -------------------------------------------------------------------------

proc group {dict} {
    set res {}
    foreach {k v} $dict {lappend res [list $k $v]}
    return $res
}

proc ignore {dict args} {
    array set tmp $dict
    foreach k $args {unset tmp($k)}
    array get tmp
}

# -------------------------------------------------------------------------
# Creation of array data sources
# Errors: Undefined variable, scalar, local variable

test tie-array-1.0 {array creation, wrong#args} {
    catch {tie::std::array} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::array::Snit_constructor type selfns win self rvar"}

test tie-array-1.1 {array creation, wrong#args} {
    catch {tie::std::array x} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::array::Snit_constructor type selfns win self rvar"}

test tie-array-1.2 {array creation, wrong#args} {
    catch {tie::std::array x y z} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::array::Snit_constructor type selfns win self rvar"}


test tie-array-1.3 {array creation, fixed name, undefined array} {
    catch {tie::std::array x y} msg
    set msg
} {Error in constructor: Undefined source array variable "y"}

test tie-array-1.4 {array creation, fixed name, proc local array} {
    proc foo {} {
	global msg
	catch {tie::std::array x y} msg
    }
    foo
    set msg
} {Error in constructor: Illegal use of proc local array variable "y"}

test tie-array-1.5 {array creation, fixed name, scalar variable} {
    unset -nocomplain av ; set av SCALAR
    catch {tie::std::array x av} msg
    set msg
} {Error in constructor: Undefined source array variable "av"}

test tie-array-1.6 {array creation, fixed name, array} {
    unset -nocomplain av ; array set av {}
    set msg [tie::std::array x av]
    x destroy
    set msg
} {::x}

test tie-array-1.7 {array creation, %AUTO%} {
    unset -nocomplain av ; array set av {}
    set msg [tie::std::array %AUTO% av]
    $msg destroy
    set msg
} {::array9}

# -------------------------------------------------------------------------
## Methods

test tie-array-2.0 {array get, wrong#args} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::array x av
    catch {x get a} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodget type selfns win self"}

test tie-array-2.1 {array get} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::array x av
    set res [dictsort [x get]]
    x destroy
    set res
} {a 1 b 2}


test tie-array-3.0 {array set, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x set} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodset type selfns win self dict"}

test tie-array-3.1 {array set, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x set a b} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodset type selfns win self dict"}

test tie-array-3.2 {array set} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    lappend res [x set {c 3 b 2 a 1}]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {a 1 b 2 c 3}}


test tie-array-4.0 {array names, wrong#args} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::array x av
    catch {x names a} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodnames type selfns win self"}

test tie-array-4.1 {array names} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::array x av
    set res [lsort [x names]]
    x destroy
    set res
} {a b}


test tie-array-5.0 {array size, wrong#args} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::array x av
    catch {x size a} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodsize type selfns win self"}

test tie-array-5.1 {array size} {
    unset -nocomplain av ; array set av {b 2 a 1}
    tie::std::array x av
    set res [x size]
    x destroy
    set res
} 2


test tie-array-6.0 {array unset, wrong#args} {
    unset -nocomplain av ; array set av {foo bar fox snarf a 3}
    tie::std::array x av
    set     res {}
    catch {x unset a b} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodunset type selfns win self ?pattern?"}

test tie-array-6.1 {array unset, default pattern} {
    unset -nocomplain av ; array set av {foo bar fox snarf a 3}
    tie::std::array x av
    set     res {}
    lappend res [x unset]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {}}

test tie-array-6.2 {array unset, by pattern} {
    unset -nocomplain av ; array set av {foo bar fox snarf a 3}
    tie::std::array x av
    set     res {}
    lappend res [x unset f*]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {a 3}}


test tie-array-7.0 {array getv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x getv} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodgetv type selfns win self index"}

test tie-array-7.1 {array getv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x getv a b} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodgetv type selfns win self index"}

test tie-array-7.2 {array getv} {
    unset -nocomplain av ; array set av {a 3 b 4}
    tie::std::array x av
    set     res {}
    lappend res [x getv a]
    x destroy
    set res
} 3


test tie-array-8.0 {array setv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x setv} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodsetv type selfns win self index value"}

test tie-array-8.1 {array setv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x setv a} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodsetv type selfns win self index value"}

test tie-array-8.2 {array setv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x setv a b c} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodsetv type selfns win self index value"}

test tie-array-8.3 {array setv} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    lappend res [x setv fox snarf]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {fox snarf}}


test tie-array-9.0 {array unsetv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x unsetv} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodunsetv type selfns win self index"}

test tie-array-9.1 {array unsetv, wrong#args} {
    unset -nocomplain av ; array set av {}
    tie::std::array x av
    set     res {}
    catch {x unsetv a b} msg
    x destroy
    set msg
} {wrong # args: should be "::tie::std::array::Snit_methodunsetv type selfns win self index"}

test tie-array-9.2 {array unsetv} {
    unset -nocomplain av ; array set av {a 3 b 4}
    tie::std::array x av
    set     res {}
    lappend res [x unsetv a]
    lappend res [dictsort [array get av]]
    x destroy
    set res
} {{} {b 4}}

testsuiteCleanup
return