1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#          Copyright (c) 1982-2011 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 <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
31bar=foo2
32bam=foo[3]
33for i in foo1 foo2 foo3 foo4 foo5 foo6
34do	foo=0
35	case $i in
36	foo1)	foo=1;;
37	$bar)	foo=2;;
38	$bam)	foo=3;;
39	foo[4])	foo=4;;
40	${bar%?}5)
41		foo=5;;
42	"${bar%?}6")
43		foo=6;;
44	esac
45	if	[[ $i != foo$foo ]]
46	then	err_exit "$i not matching correct pattern"
47	fi
48done
49f="[ksh92]"
50case $f in
51\[*\])  ;;
52*)      err_exit "$f does not match \[*\]";;
53esac
54
55if	[[ $($SHELL -c '
56		x=$(case abc {
57			abc)	{ print yes;};;
58			*)	 print no;;
59			}
60		)
61		print -r -- "$x"' 2> /dev/null) != yes ]]
62then err_exit 'case abc {...} not working'
63fi
64[[ $($SHELL -c 'case a in
65a)      print -n a > /dev/null ;&
66b)      print b;;
67esac') != b ]] && err_exit 'bug in ;& at end of script'
68[[ $(VMDEBUG=1 $SHELL -c '
69	tmp=foo
70	for i in a b
71	do	case $i in
72		a)	:  tmp=$tmp tmp.h=$tmp.h;;
73		b)	( tmp=bar )
74			for j in a
75			do	print -r -- $tmp.h
76			done
77			;;
78		esac
79	done
80') == foo.h ]] || err_exit "optimizer bug"
81
82x=$($SHELL -ec 'case a in a) echo 1; false; echo 2 ;& b) echo 3;; esac')
83[[ $x == 1 ]] || err_exit 'set -e ignored on case fail through'
84
85exit $((Errors<125?Errors:125))
86