xref: /titanic_41/usr/src/lib/libshell/common/tests/append.sh (revision 186f7fbf5e07d046b50e4e15c32b21f109b76c80)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#           Copyright (c) 1982-2007 AT&T Knowledge Ventures            #
5#                      and is licensed under the                       #
6#                  Common Public License, Version 1.0                  #
7#                      by AT&T Knowledge Ventures                      #
8#                                                                      #
9#                A copy of the License is available at                 #
10#            http://www.opensource.org/licenses/cpl1.0.txt             #
11#         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                  David Korn <dgk@research.att.com>                   #
18#                                                                      #
19########################################################################
20function err_exit
21{
22	print -u2 -n "\t"
23	print -u2 -r ${Command}[$1]: "${@:2}"
24	let Errors+=1
25}
26alias err_exit='err_exit $LINENO'
27
28Command=${0##*/}
29integer Errors=0
30{
31x=abc
32x+=def ;} 2> /dev/null
33if	[[ $x != abcdef ]]
34then	err_exit 'abc+def != abcdef'
35fi
36integer i=3
37{ i+=4;} 2> /dev/null
38if	(( i != 7 ))
39then	err_exit '3+4!=7'
40fi
41iarray=( one two three )
42{ iarray+= (four five six) ;} 2> /dev/null
43if	[[ ${iarray[@]} != 'one two three four five six' ]]
44then	err_exit 'index array append fails'
45fi
46unset iarray
47iarray=one
48{ iarray+= (four five six) ;} 2> /dev/null
49if	[[ ${iarray[@]} != 'one four five six' ]]
50then	err_exit 'index array append to scalar fails'
51fi
52typeset -A aarray
53aarray=( [1]=1 [3]=4 [xyz]=xyz )
54aarray+=( [2]=2 [3]=3 [foo]=bar )
55if	[[ ${aarray[3]} != 3 ]]
56then	err_exit 'associative array append fails'
57fi
58if	[[ ${#aarray[@]} != 5 ]]
59then	err_exit 'number of elements of associative array append fails'
60fi
61point=(x=1 y=2)
62point+=( y=3 z=4)
63if	[[ ${point.y} != 3 ]]
64then	err_exit 'compound append fails'
65fi
66unset foo
67foo=one
68foo+=(two)
69if	[[ ${foo[@]} != 'one two' ]]
70then	err_exit 'array append to non array variable fails'
71fi
72exit $((Errors))
73