1 ########################################################################
3 # This software is part of the ast package #
4 # Copyright (c) 1982-2010 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Common Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
9 # A copy of the License is available at #
10 # http://www.opensource.org/licenses/cpl1.0.txt #
11 # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
13 # Information and Software Systems Research #
17 # David Korn <dgk@research.att.com> #
19 ########################################################################
23 print
-u2 -r ${Command}[$1]: "${@:2}"
26 alias err_exit
='err_exit $LINENO'
28 #test for compound variables
35 if (( (p.x
*p.x
+ p.y
*p.y
) > 1.01 ))
36 then err_exit
'compound variable not working'
39 if [[ ${foo.x} != ${Point.x} ]]
40 then err_exit
'reference to compound object not working'
52 if [[ ${newrec.name} != "${rec.name}" ]]
53 then err_exit
'copying a compound object not working'
55 if (( newrec.born.day
!= 16 ))
56 then err_exit
'copying integer field of compound object not working'
65 if [[ ${x[@]} != bar
]]
66 then err_exit
'compound assignemnt of associative arrays not working'
72 if [[ ${!x.@} != foo.x
]]
73 then err_exit
'name references not expanded on prefix matching'
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* ]]'
85 if [[ ${foo} != *x
=3* ]]
86 then err_exit
"compound variable with integer subvariable not working"
88 $SHELL -c $
'x=(foo=bar)\n[[ x == x ]]' 2> /dev
/null ||
89 err_exit
'[[ ... ]] not working after compound assignment'
91 [[ ${!foo.@} ]] && err_exit
'unset compound variable leaves subvariables'
99 label
="Table Viewer Preferences"
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 \
109 type=coord var
=vieworigin val
="0 0" label
="Window Position"
112 type=coord var
=viewsize val
="400 400" label
="Window Size"
115 type=2colors var
=viewcolor val
="gray black"
116 label
="Window Colors"
119 type=fontname var
=viewfontname val
="Times-Roman"
120 label
="Window Font Name"
123 type=fontsize var
=viewfontsize val
=14 label
="Window Font Size"
127 type=yesno var
=showheader val
=no label
="Show Header"
130 type=text var
=header val
="" label
="Header"
134 type=yesno var
=showfooter val
=no label
="Show Footer"
137 type=text var
=footer val
="" label
="Footer"
141 type=yesno var
=showtitle val
=yes label
="Show Title"
144 type=text var
=title val
="SWIFTUI - Table View" label
="Title"
148 type=yesno var
=showlegends val
=yes label
="Show Legends"
152 type=style var
=class_td_lg1_style
153 val
="color: black; font-family: Times-Roman; font-size: 14pt"
154 label
="Legend 1 Style"
158 type=style var
=class_tr_tr1_style val
="background: black"
159 label
="Table Row 1 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"
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"
175 type=text var
=fields val
= label
="List of Fields"
178 type=text var
=fieldorder val
= label
="Order of Fields"
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'
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"
191 point
=(integer x
=6 y
=8)
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'
198 then print
-r -- "$point"
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"
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'
210 ( typeset
-S x
=+++)2> /dev
/null || err_exit
"typeset -S doesn't unset first"
213 ( [[ ${z.foo.bar:-abc} == abc
]] 2> /dev
/null
) || err_exit
':- not working with compound variables'
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'
225 [[ ${a.z} == 3 ]] && err_exit
"\${a.z} should not be 3"
229 [[ ${a.z} == 3 ]] && err_exit
'a.z should not be set to 3'
234 { b
=( b1
=${a.b} ) ;} 2> /dev
/null
235 [[ ${b.b1} == foo
]] || err_exit
'${b.b1} should be foo'
240 { print ${.sh.name}=${.sh.value}; }'
244 eval 'b=(typeset x=0; typeset y=0 )
246 { print ${.sh.name}=${.sh.value}; }'
249 [[ ${ a=123;} == 'a=123' ]] || err_exit
'should be a=123'
251 [[ ${ b.x=456;} == 'b.x=456' ]] || err_exit
'should be b.x=456'
252 eval 'b=(typeset x=0; typeset y=0 )
254 { print ${.sh.name}=${.sh.value}; }' > /dev
/null
255 [[ ${ b.x=789;} == 'b.x=789' ]] || err_exit
'should be b.x=789'
265 [[ $X == $
'(\n\tfoo=1\n)' ]] || err_exit
'scoping problem with compound variables'
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'
272 [[ $foo == *'typeset -a bar'* ]] || err_exit
'array attribute -a not preserved in compound variable'
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'
278 nodes
[0]+=( integer x
=5)
279 [[ ${nodes[0].x} == 5 ]] || err_exit
'${nodes[0].x} should be 5'
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'
289 typeset
-A array
=([one
]=one
[two
]=2)
293 foo2.hello
=notok foo2.
yes.yex
=no foo2.extra
=yes.
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
319 [[ $x == "$y" ]] || err_exit '$x != $y with set | grep'
321 x=( float x=0 y=1; z=([foo]=abc [bar]=def))
323 [[ $x == "$y" ]] || err_exit '$x != $y with typeset -C'
327 [[ $x == "$y" ]] || err_exit '$x != $y when x=y and x and y are -C '
332 [[ $x == "$z" ]] || err_exit '$x != $z when x=z and x and z are -C '
335 [[ $x == "$y" ]] || err_exit '$x != $y when x=y -C copied in a function '
338 [[ $y == *foo=abc* ]] || err_exit 'z not appended to y'
340 [[ $x == "$y" ]] || err_exit '$x != $y when y.foo deleted'
342 x=( foo=(z=abc d=ghi) bar=abc; typeset -A r=([x]=3 [y]=4))
345 [[ $x == $'(\n)' ]] || err_exit 'unset compound variable is not empty'
349 z.foo=( [one]=hello [two]=(x=3 y=4) [three]=hi)
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"
386 exp=$'(\n\ttypeset -a x=(\n\t\t[1]=(\n\t\t\tX=1\n\t\t)\n\t)\n)'
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"
402 exp=$'(\n\ttypeset -a x=(\n\t\t[1]=(\n\t\t\tX=1\n\t\t)\n\t)\n)'
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"
410 # array of compund variables
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'
437 foo 2> /dev/null <<- \
EOF || err_exit 'deleting compound variable in function failed'
439 typeset -A myarray3=(
455 mica01[4]=( a_string="foo bar" )
456 typeset -C more_content=(
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'
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"
469 typeset -C -A hello19=(
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'
484 typeset -C -A foo1=( abc="alphabet" ) foo2=( abc="alphabet" )
493 nameref node1="foo1[1234]"
496 [[ "${foo1[1234]}" == "${foo2[1234]}" ]] || err_exit "test failed\n$(diff -u <( print -r -- "${foo1[1234]}") <(print -r -- "${foo2[1234]}"))."
502 typeset -A tr.subtree
507 # move local note into the array
508 typeset -m tr.subtree["a_node"]=node
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'
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'
532 [[ $output == *end=* ]] || err_exit "The field 'name' end is missing"
534 compound cpv1=( integer f=2 )
539 [[ $x == *f=2* ]] || err_exit "The field b containg 'f=2' is missing"