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