Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ksh93/tests/comvar.sh
1810 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1982-2012 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# #
19
########################################################################
20
function err_exit
21
{
22
print -u2 -n "\t"
23
print -u2 -r ${Command}[$1]: "${@:2}"
24
let Errors+=1
25
}
26
alias err_exit='err_exit $LINENO'
27
28
#test for compound variables
29
Command=${0##*/}
30
integer Errors=0
31
Point=(
32
float x=1. y=0.
33
)
34
eval p="$Point"
35
if (( (p.x*p.x + p.y*p.y) > 1.01 ))
36
then err_exit 'compound variable not working'
37
fi
38
nameref foo=p
39
if [[ ${foo.x} != ${Point.x} ]]
40
then err_exit 'reference to compound object not working'
41
fi
42
unset foo
43
rec=(
44
name='Joe Blow'
45
born=(
46
month=jan
47
integer day=16
48
year=1980
49
)
50
)
51
eval newrec="$rec"
52
if [[ ${newrec.name} != "${rec.name}" ]]
53
then err_exit 'copying a compound object not working'
54
fi
55
if (( newrec.born.day != 16 ))
56
then err_exit 'copying integer field of compound object not working'
57
fi
58
p_t=(
59
integer z=0
60
typeset -A tokens
61
)
62
unset x
63
typeset -A x
64
x=( [foo]=bar )
65
if [[ ${x[@]} != bar ]]
66
then err_exit 'compound assignemnt of associative arrays not working'
67
fi
68
unset -n foo x
69
unset foo x
70
foo=( x=3)
71
nameref x=foo
72
if [[ ${!x.@} != foo.x ]]
73
then err_exit 'name references not expanded on prefix matching'
74
fi
75
unset x
76
unset -n x
77
(
78
x=()
79
x.foo.bar=7
80
[[ ${x.foo.bar} == 7 ]] || err_exit '[[ ${x.foo.bar} != 7 ]]'
81
(( x.foo.bar == 7 ))|| err_exit '(( x.foo.bar != 7 ))'
82
[[ ${x.foo} == *bar=7* ]] || err_exit '[[ ${x.foo} != *bar=7* ]]'
83
)
84
foo=(integer x=3)
85
if [[ ${foo} != *x=3* ]]
86
then err_exit "compound variable with integer subvariable not working"
87
fi
88
$SHELL -c $'x=(foo=bar)\n[[ x == x ]]' 2> /dev/null ||
89
err_exit '[[ ... ]] not working after compound assignment'
90
unset foo
91
[[ ${!foo.@} ]] && err_exit 'unset compound variable leaves subvariables'
92
suitable=(
93
label="Table Viewer"
94
langs="ksh"
95
uselang=ksh
96
launch=no
97
groups="default"
98
default=(
99
label="Table Viewer Preferences"
100
entrylist=" \
101
vieworigin viewsize viewcolor viewfontname viewfontsize \
102
showheader header showfooter footer showtitle title showlegends \
103
class_td_lg1_style class_tr_tr1_style \
104
class_th_th1_style class_td_td1_style \
105
fields fieldorder \
106
"
107
entries=(
108
vieworigin=(
109
type=coord var=vieworigin val="0 0" label="Window Position"
110
)
111
viewsize=(
112
type=coord var=viewsize val="400 400" label="Window Size"
113
)
114
viewcolor=(
115
type=2colors var=viewcolor val="gray black"
116
label="Window Colors"
117
)
118
viewfontname=(
119
type=fontname var=viewfontname val="Times-Roman"
120
label="Window Font Name"
121
)
122
viewfontsize=(
123
type=fontsize var=viewfontsize val=14 label="Window Font Size"
124
)
125
126
showheader=(
127
type=yesno var=showheader val=no label="Show Header"
128
)
129
header=(
130
type=text var=header val="" label="Header"
131
)
132
133
showfooter=(
134
type=yesno var=showfooter val=no label="Show Footer"
135
)
136
footer=(
137
type=text var=footer val="" label="Footer"
138
)
139
140
showtitle=(
141
type=yesno var=showtitle val=yes label="Show Title"
142
)
143
title=(
144
type=text var=title val="SWIFTUI - Table View" label="Title"
145
)
146
147
showlegends=(
148
type=yesno var=showlegends val=yes label="Show Legends"
149
)
150
151
class_td_lg1_style=(
152
type=style var=class_td_lg1_style
153
val="color: black; font-family: Times-Roman; font-size: 14pt"
154
label="Legend 1 Style"
155
)
156
157
class_tr_tr1_style=(
158
type=style var=class_tr_tr1_style val="background: black"
159
label="Table Row 1 Style"
160
)
161
162
class_th_th1_style=(
163
type=style var=class_th_th1_style
164
val="color: black; font-family: Times-Roman; font-size: 14pt; text-align: left"
165
label="Table Header 1 Style"
166
)
167
168
class_td_td1_style=(
169
type=style var=class_td_td1_style
170
val="color: black; font-family: Times-Roman; font-size: 14pt; text-align: left"
171
label="Table Cell 1 Style"
172
)
173
174
fields=(
175
type=text var=fields val= label="List of Fields"
176
)
177
fieldorder=(
178
type=text var=fieldorder val= label="Order of Fields"
179
)
180
)
181
)
182
)
183
[[ "${suitable}" == *entrylist=* ]] || err_exit 'compound variable expansion omitting fields'
184
foo=( bar=foo barbar=bar)
185
[[ $foo == *bar=foo* ]] || err_exit 'no prefix elements in compound variable output'
186
function localvar
187
{
188
typeset point=(typeset -i x=3 y=4)
189
(( (point.x*point.x + point.y*point.y) == 25 )) || err_exit "local compound variable not working"
190
}
191
point=(integer x=6 y=8)
192
localvar
193
(( (point.x*point.x + point.y*point.y) == 100 )) || err_exit "global compound variable not preserved"
194
[[ $($SHELL -c 'foo=();foo.[x]=(y z); print ${foo.x[@]}') == 'y z' ]] 2> /dev/null || err_exit 'foo=( [x]=(y z) not working'
195
function staticvar
196
{
197
if [[ $1 ]]
198
then print -r -- "$point"
199
return
200
fi
201
typeset -S point=(typeset -i x=3 y=4)
202
(( (point.x*point.x + point.y*point.y) == 25 )) || err_exit "local compound variable not working"
203
point.y=5
204
point.z=foobar
205
}
206
staticvar
207
(( (point.x*point.x + point.y*point.y) == 100 )) || err_exit "global compound variable not preserved"
208
[[ $(staticvar x) == $'(\n\ttypeset -i x=3\n\ttypeset -i y=5\n\tz=foobar\n)' ]] || err_exit 'static variables in function not working'
209
integer x=3
210
( typeset -S x=+++)2> /dev/null || err_exit "typeset -S doesn't unset first"
211
212
unset z
213
( [[ ${z.foo.bar:-abc} == abc ]] 2> /dev/null) || err_exit ':- not working with compound variables'
214
stack=()
215
typeset -a stack.items=([0]=foo [1]=bar)
216
[[ ${stack.items[0]} == foo ]] || err_exit 'typeset -a variable not expanding correctly'
217
$SHELL -c 'typeset -a info=( [1]=( passwd=( since=2005-07-20) ))' || err_exit 'problem with embedded index array in compound variable'
218
x=(foo=([1]=(y=([2]=(z=4)))))
219
[[ $x == *'.y'=* ]] && err_exit 'expansion with bogus leading . in name'
220
unset z
221
z=1
222
function foo
223
{
224
z=3
225
[[ ${a.z} == 3 ]] && err_exit "\${a.z} should not be 3"
226
print hi
227
}
228
a=( b=$(foo) )
229
[[ ${a.z} == 3 ]] && err_exit 'a.z should not be set to 3'
230
function a.b.get
231
{
232
.sh.value=foo
233
}
234
{ b=( b1=${a.b} ) ;} 2> /dev/null
235
[[ ${b.b1} == foo ]] || err_exit '${b.b1} should be foo'
236
function dcl1
237
{
238
eval 'a=1
239
function a.set
240
{ print ${.sh.name}=${.sh.value}; }'
241
}
242
function dcl2
243
{
244
eval 'b=(typeset x=0; typeset y=0 )
245
function b.x.set
246
{ print ${.sh.name}=${.sh.value}; }'
247
}
248
dcl1
249
[[ ${ a=123;} == 'a=123' ]] || err_exit 'should be a=123'
250
dcl2
251
[[ ${ b.x=456;} == 'b.x=456' ]] || err_exit 'should be b.x=456'
252
eval 'b=(typeset x=0; typeset y=0 )
253
function b.x.set
254
{ print ${.sh.name}=${.sh.value}; }' > /dev/null
255
[[ ${ b.x=789;} == 'b.x=789' ]] || err_exit 'should be b.x=789'
256
unset a b
257
function func
258
{
259
typeset X
260
X=( bar=2 )
261
}
262
263
X=( foo=1 )
264
func
265
[[ $X == $'(\n\tfoo=1\n)' ]] || err_exit 'scoping problem with compound variables'
266
unset foo
267
typeset -A foo=([a]=aa;[b]=bb;[c]=cc)
268
[[ ${foo[c]} == cc ]] || err_exit 'associative array assignment with; not working'
269
[[ $({ $SHELL -c 'x=(); typeset -a x.foo; x.foo=bar; print -r -- "$x"' ;} 2> /dev/null) == $'(\n\ttypeset -a foo=bar\n)' ]] || err_exit 'indexed array in compound variable with only element 0 defined fails'
270
unset foo
271
foo=(typeset -a bar)
272
[[ $foo == *'typeset -a bar'* ]] || err_exit 'array attribute -a not preserved in compound variable'
273
unset s
274
typeset -A s=( [foo]=(y=2 z=3) [bar]=(y=4 z=5))
275
[[ ${s[@]} == *z=*z=* ]] || err_exit 'missing elements in compound associative array'
276
unset nodes
277
typeset -A nodes
278
nodes[0]+=( integer x=5)
279
[[ ${nodes[0].x} == 5 ]] || err_exit '${nodes[0].x} should be 5'
280
unset foo
281
typeset -C foo
282
foo.bar=abc
283
[[ $foo == $'(\n\tbar=abc\n)' ]] || err_exit 'typeset -C not working for foo'
284
typeset -C foo=(bar=def)
285
[[ $foo == $'(\n\tbar=def\n)' ]] || err_exit 'typeset -C not working when initialized'
286
foo=(
287
hello=ok
288
yes=( bam=2 yes=4)
289
typeset -A array=([one]=one [two]=2)
290
last=me
291
)
292
eval foo2="$foo"
293
foo2.hello=notok foo2.yes.yex=no foo2.extra=yes.
294
typeset -C bar bam
295
{
296
read -Cu3 bar
297
read -Cu3 bam
298
read -ru3
299
} 3<<- ++++
300
"$foo"
301
"$foo2"
302
last line
303
++++
304
[[ $? == 0 ]] || err_exit ' read -C failed'
305
[[ $bar == "$foo" ]] || err_exit '$foo != $bar'
306
[[ $bam == "$foo2" ]] || err_exit '$foo2 != $bmr'
307
[[ $REPLY == 'last line' ]] || err_exit "\$REPLY=$REPLY should be 'last line"
308
typeset x=( typeset -a foo=( [1][3]=hello [9][2]="world" ) )
309
eval y="(typeset -a foo=$(printf "%B\n" x.foo) )"
310
[[ $x == "$y" ]] || err_exit '$x.foo != $y.foo with %B'
311
eval y="(typeset -a foo=$(printf "%#B\n" x.foo) )"
312
[[ $x == "$y" ]] || err_exit '$x.foo != $y.foo with %#B'
313
eval y="$(printf "%B\n" x)"
314
[[ $x == "$y" ]] || err_exit '$x != $y with %B'
315
eval y="$(printf "%#B\n" x)"
316
[[ $x == "$y" ]] || err_exit '$x != $y with %#B'
317
y=$(set | grep ^x=) 2> /dev/null
318
eval "${y/#x/y}"
319
[[ $x == "$y" ]] || err_exit '$x != $y with set | grep'
320
unset x y z
321
x=( float x=0 y=1; z=([foo]=abc [bar]=def))
322
typeset -C y=x
323
[[ $x == "$y" ]] || err_exit '$x != $y with typeset -C'
324
unset y
325
y=()
326
y=x
327
[[ $x == "$y" ]] || err_exit '$x != $y when x=y and x and y are -C '
328
function foobar
329
{
330
typeset -C z
331
z=x
332
[[ $x == "$z" ]] || err_exit '$x != $z when x=z and x and z are -C '
333
y=z
334
}
335
[[ $x == "$y" ]] || err_exit '$x != $y when x=y -C copied in a function '
336
z=(foo=abc)
337
y+=z
338
[[ $y == *foo=abc* ]] || err_exit 'z not appended to y'
339
unset y.foo
340
[[ $x == "$y" ]] || err_exit '$x != $y when y.foo deleted'
341
unset x y
342
x=( foo=(z=abc d=ghi) bar=abc; typeset -A r=([x]=3 [y]=4))
343
unset x
344
x=()
345
[[ $x == $'(\n)' ]] || err_exit 'unset compound variable is not empty'
346
347
unset z
348
z=()
349
z.foo=( [one]=hello [two]=(x=3 y=4) [three]=hi)
350
z.bar[0]=hello
351
z.bar[2]=world
352
z.bar[1]=(x=4 y=5)
353
exp='(
354
typeset -a bar=(
355
[0]=hello
356
[2]=world
357
[1]=(
358
x=4
359
y=5
360
)
361
)
362
typeset -A foo=(
363
[one]=hello
364
[three]=hi
365
[two]=(
366
x=3
367
y=4
368
)
369
)
370
)'
371
got=$z
372
[[ $got == "$exp" ]] || {
373
exp=$(printf %q "$exp")
374
got=$(printf %q "$got")
375
err_exit "compound indexed array pretty print failed -- expected $exp, got $got"
376
}
377
378
typeset -A record
379
record[a]=(
380
typeset -a x=(
381
[1]=(
382
X=1
383
)
384
)
385
)
386
exp=$'(\n\ttypeset -a x=(\n\t\t[1]=(\n\t\t\tX=1\n\t\t)\n\t)\n)'
387
got=${record[a]}
388
[[ $got == "$exp" ]] || {
389
exp=$(printf %q "$exp")
390
got=$(printf %q "$got")
391
err_exit "compound indexed array pretty print failed -- expected $exp, got $got"
392
}
393
394
unset r
395
r=(
396
typeset -a x=(
397
[1]=(
398
X=1
399
)
400
)
401
)
402
exp=$'(\n\ttypeset -a x=(\n\t\t[1]=(\n\t\t\tX=1\n\t\t)\n\t)\n)'
403
got=$r
404
[[ $got == "$exp" ]] || {
405
exp=$(printf %q "$exp")
406
got=$(printf %q "$got")
407
err_exit "compound indexed array pretty print failed -- expected $exp, got $got"
408
}
409
410
# array of compund variables
411
typeset -C data=(
412
typeset -a samples
413
)
414
data.samples+=(
415
type1="greeting1"
416
timestamp1="now1"
417
command1="grrrr1"
418
)
419
data.samples+=(
420
type2="greeting2"
421
timestamp2="now2"
422
command2="grrrr2"
423
)
424
425
[[ $data == %(()) ]] || err_exit "unbalanced parenthesis with compound variable containing array of compound variables"
426
typeset -C -A hello=( [foo]=bar)
427
[[ $(typeset -p hello) == 'typeset -C -A hello=([foo]=bar)' ]] || err_exit 'typeset -A -C with intial assignment not working'
428
# this caused a core dump before ksh93t+
429
[[ $($SHELL -c 'foo=(x=3 y=4);function bar { typeset z=4;: $z;};bar;print ${!foo.@}') == 'foo.x foo.y' ]] 2> /dev/null || err_exit '${!foo.@} after function not working'
430
431
function foo
432
{
433
typeset tmp
434
read -C tmp
435
read -C tmp
436
}
437
foo 2> /dev/null <<- \EOF || err_exit 'deleting compound variable in function failed'
438
(
439
typeset -A myarray3=(
440
[a]=( foo=bar)
441
[b]=( foo=bar)
442
[c d]=( foo=bar)
443
[e]=( foo=bar)
444
[f]=( foo=bar)
445
[g]=( foo=bar)
446
[h]=( foo=bar)
447
[i]=( foo=bar)
448
[j]=( foo=bar)
449
)
450
)
451
hello
452
EOF
453
454
typeset -C -a mica01
455
mica01[4]=( a_string="foo bar" )
456
typeset -C more_content=(
457
some_stuff="hello"
458
)
459
mica01[4]+=more_content
460
expected=$'typeset -C -a mica01=([4]=(a_string=\'foo bar\';some_stuff=hello))'
461
[[ $(typeset -p mica01) == "$expected" ]] || err_exit 'appened to indexed array compound variable not working'
462
463
unset x
464
compound x=( integer x ; )
465
[[ ! -v x.x ]] && err_exit 'x.x should be set'
466
expected=$'(\n\ttypeset -l -i x=0\n)'
467
[[ $(print -v x) == "$expected" ]] || err_exit "'print -v x' should be $expected"
468
469
typeset -C -A hello19=(
470
[19]=(
471
one="xone 19"
472
two="xtwo 19"
473
)
474
[23]=(
475
one="xone 23"
476
two="xtwo 23"
477
)
478
)
479
expected="typeset -C -A hello19=([19]=(one='xone 19';two='xtwo 19') [23]=(one='xone 23';two='xtwo 23'))"
480
[[ $(typeset -p hello19) == "$expected" ]] || print -u2 'typeset -p hello19 incorrect'
481
expected=$'(\n\tone=\'xone 19\'\n\ttwo=\'xtwo 19\'\n) (\n\tone=\'xone 23\'\n\ttwo=\'xtwo 23\'\n)'
482
[[ ${hello19[@]} == "$expected" ]] || print -u2 '${hello19[@]} incorrect'
483
484
typeset -C -A foo1=( abc="alphabet" ) foo2=( abc="alphabet" )
485
function add_one
486
{
487
nameref left_op=$1
488
typeset -C info
489
info.hello="world"
490
nameref x=info
491
left_op+=x
492
}
493
nameref node1="foo1[1234]"
494
add_one "node1"
495
add_one "foo2[1234]"
496
[[ "${foo1[1234]}" == "${foo2[1234]}" ]] || err_exit "test failed\n$(diff -u <( print -r -- "${foo1[1234]}") <(print -r -- "${foo2[1234]}"))."
497
498
typeset -C tree
499
function f1
500
{
501
nameref tr=$1
502
typeset -A tr.subtree
503
typeset -C node
504
node.one="hello"
505
node.two="world"
506
507
# move local note into the array
508
typeset -m tr.subtree["a_node"]=node
509
}
510
f1 tree
511
expected=$'(\n\ttypeset -A subtree=(\n\t\t[a_node]=(\n\t\t\tone=hello\n\t\t\ttwo=world\n\t\t)\n\t)\n)'
512
[[ $tree == "$expected" ]] || err_exit 'move of compound local variable to global variable not working'
513
514
typeset -C -A array
515
float array[12].amount=2.9
516
expected='typeset -C -A array=([12]=(typeset -l -E amount=2.9))'
517
[[ $(typeset -p array) == "$expected" ]] || err_exit 'typeset with compound variable with compound variable array not working'
518
519
typeset -T foo_t=(
520
function diff
521
{
522
print 1.0
523
return 0
524
}
525
)
526
foo_t sw
527
compound output=(
528
integer one=1
529
float mydiff=sw.diff
530
float end=.314
531
)
532
[[ $output == *end=* ]] || err_exit "The field 'name' end is missing"
533
534
compound cpv1=( integer f=2 )
535
compound x=(
536
integer a=1
537
compound b=cpv1
538
)
539
[[ $x == *f=2* ]] || err_exit "The field b containg 'f=2' is missing"
540
541
unset x
542
compound x=(
543
compound -a nodes=(
544
[4]=( )
545
)
546
)
547
expected='typeset -C x=(typeset -C -a nodes=([4]=());)'
548
[[ $(typeset -p x) == "$expected" ]] || err_exit 'typeset -p with nested compound index array not working'
549
550
unset v
551
compound v=(
552
integer -A ar=(
553
[aa]=4 [bb]=9
554
)
555
)
556
expected='typeset -C v=(typeset -A -l -i ar=([aa]=4 [bb]=9);)'
557
[[ $(typeset -p v) == "$expected" ]] || err_exit 'attributes for associative arrays embedded in compound variables not working'
558
559
unset x
560
compound -a x
561
x[1]=( a=1 b=2 )
562
[[ $(print -v x[1]) == "${x[1]}" ]] || err_exit 'print -v x[1] not working for index array of compound variables'
563
564
unset x
565
z='typeset -a x=(hello (x=12;y=5) world)'
566
{ eval "$z" ;} 2> /dev/null
567
[[ $(typeset -p x) == "$z" ]] || err_exit "compound assignment '$z' not working"
568
569
expected='typeset -C -A l=([4]=(typeset -a ar=(1 2 3);b=1))'
570
typeset -A -C l
571
printf "( typeset -a ar=( 1\n2\n3\n) b=1 )\n" | read -C l[4]
572
[[ $(typeset -p l) == "$expected" ]] || err_exit 'read -C for associative array of compound variables not working'
573
574
unset x
575
compound x=( z="a=b c")
576
exp=$'typeset -C x=(z=a\\=\'b c\')'
577
got=$(typeset -p x)
578
[[ $got == "$exp" ]] || err_exit "typeset -p failed -- expected '$exp', got '$got'"
579
580
x=(typeset -C -a y;float z=2)
581
got=$(print -C x)
582
expected='(typeset -C -a y;typeset -l -E z=2)'
583
[[ $expected == "$got" ]] || err_exit "print -C x exects '$expected' got '$got'"
584
585
unset vx vy
586
compound vx=(
587
compound -a va=(
588
[3][17]=(
589
integer -A ar=( [aa]=4 [bb]=9 )
590
)
591
)
592
)
593
eval "vy=$(print -C vx)"
594
[[ $vx == "$vy" ]] || err_exit 'print -C with multi-dimensional array not working'
595
eval "vy=$(print -v vx)"
596
[[ $vx == "$vy" ]] || err_exit 'print -v with multi-dimensional array not working'
597
598
unset x
599
typeset -C -A x=( [0]=(a=1) [1]=(b=2) )
600
expected=$'(\n\t[0]=(\n\t\ta=1\n\t)\n\t[1]=(\n\t\tb=2\n\t)\n)'
601
[[ $(print -v x) == "$expected" ]] || err_exit 'print -v not formatting correctly'
602
603
compound -a x=( [0]=(a=1) [1]=(b=2) )
604
typeset -m "z=x[1]"
605
[[ $(typeset -p z 2>/dev/null) == 'typeset -C z=(b=2)' ]] || err_exit 'typeset -m not working with commpound -a variable'
606
607
unset x z
608
compound -A x=( [0]=(a=1) [1]=(b=2) )
609
typeset -m "z=x[1]"
610
[[ $(typeset -p z 2>/dev/null) == 'typeset -C z=(b=2)' ]] || err_exit 'typeset -m not working with commpound -a variable'
611
typeset -m "x[1]=x[0]"
612
typeset -m "x[0]=z"
613
exp='([0]=(b=2) [1]=(a=1))'
614
[[ $(print -C x) == "$exp" ]] || err_exit 'typeset -m not working for associative arrays'
615
616
unset z r
617
z=(a b c)
618
r=(x=3 y=4)
619
typeset -m z[1]=r
620
exp='typeset -a z=(a (x=3;y=4) c)'
621
[[ $(typeset -p z) == "$exp" ]] || err_exit 'moving compound variable into indexed array fails'
622
623
unset c
624
compound c
625
compound -a c.a=( [1]=( aa=1 ) )
626
compound -a c.b=( [2]=( bb=2 ) )
627
typeset -m "c.b[9]=c.a[1]"
628
exp='typeset -C c=(typeset -C -a a;typeset -C -a b=( [2]=(bb=2;)[9]=(aa=1));)'
629
[[ $(typeset -p c) == "$exp" ]] || err_exit 'moving compound indexed array element to another index fails'
630
631
unset c
632
compound c
633
compound -a c.a=( [1]=( aa=1 ) )
634
compound -A c.b=( [2]=( bb=2 ) )
635
typeset -m "c.b[9]=c.a[1]"
636
exp='typeset -C c=(typeset -C -a a;typeset -C -A b=( [2]=(bb=2;)[9]=(aa=1));)'
637
[[ $(typeset -p c) == "$exp" ]] || err_exit 'moving compound indexed array element to a compound associative array element fails'
638
639
zzz=(
640
foo=(
641
bar=4
642
)
643
)
644
[[ $(set | grep "^zzz\.") ]] && err_exit 'set displays compound variables incorrectly'
645
646
typeset -A stats
647
stats[1]=(a=1 b=2)
648
stats[2]=(a=1 b=2)
649
stats[1]=(c=3 d=4)
650
(( ${#stats[@]} == 2 )) || err_exit "stats[1] should contain 2 element not ${#stats[@]}"
651
652
integer i=1
653
foo[i++]=(x=3 y=4)
654
[[ ${foo[1].x} == 3 ]] || err_exit "\${foo[1].x} should be 3"
655
[[ ${foo[1].y} == 4 ]] || err_exit "\${foo[1].y} should be 4"
656
657
# ${!x.} caused core dump in ks93u and earlier
658
{ $SHELL -c 'compound x=(y=1); : ${!x.}' ; ((!$?));} || err_exit '${!x.} not working'
659
660
$SHELL -c 'typeset -A a=([b]=c)' 2> /dev/null || err_exit 'typeset -A a=([b]=c) fails'
661
662
compound -a a
663
compound c=( name="container1" )
664
a[4]=c
665
[[ ${a[4]} == $'(\n\tname=container1\n)' ]] || err_exit 'assignment of compound variable to compound array element not working'
666
667
unset c
668
compound c
669
compound -a c.board
670
for ((i=2; i < 4; i++))
671
do c.board[1][$i]=(foo=bar)
672
done
673
exp=$'(\n\ttypeset -C -a board=(\n\t\t[1]=(\n\t\t\t[2]=(\n\t\t\t\tfoo=bar\n\t\t\t)\n\t\t\t[3]=(\n\t\t\t\tfoo=bar\n\t\t\t)\n\t\t)\n\t)\n)'
674
[[ "$(print -v c)" == "$exp" ]] || err_exit 'compound variable assignment to two dimensional array not working'
675
676
unset zz
677
zz=()
678
zz.[foo]=abc
679
zz.[2]=def
680
exp='typeset -C zz=([2]=def;foo=abc)'
681
[[ $(typeset -p zz) == "$exp" ]] || err_exit 'expansion of compound variables with non-identifiers not working'
682
(
683
typeset -i zz.[3]=123
684
exec 2>& 3-
685
exp='typeset -C zz=([2]=def;typeset -i [3]=123;foo=abc)'
686
[[ $(typeset -p zz) == "$exp" ]] || err_exit 'expansion of compound variables with non-identifiers not working in subshells'
687
) 3>&2 2> /dev/null || err_exit 'syntax errors expansion of compound variables with non-identifiers'
688
689
unset xx
690
xx=(foo=bar)
691
xx=()
692
[[ $xx == $'(\n)' ]] || err_exit 'xx=() not unsetting previous value'
693
694
exit $((Errors<125?Errors:125))
695
696