]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/case.tests
Bash-5.2 patch 26: fix typo when specifying readline's custom color prefix
[thirdparty/bash.git] / tests / case.tests
1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 #
14 case foo in
15 bar) echo skip ;;
16 foo) echo fallthrough ;&
17 bax) echo to here ;&
18 qux) echo and here;;
19 fop) echo but not here;;
20 esac
21
22 case foobar in
23 bar) echo skip ;;
24 foo*) echo retest ;;&
25 *bar) echo and match ;;&
26 qux) echo but not this ;;
27 esac
28
29 case a in
30 a) echo no more clauses;&
31 esac
32
33 x=0 y=1
34 case 1 in
35 $((y=0)) ) ;;
36 $((x=1)) ) ;&
37 $((x=2)) ) echo $x.$y ;;
38 esac
39
40 unset x
41 readonly xx=1
42 case 1 in $((xx++)) ) echo hi1 ;; *) echo hi2; esac
43 echo ${xx}.$?
44
45 unset var empty
46
47 var=
48 case ']' in
49 [$var]*[$var]) echo matches 1;;
50 *) echo no match 1 ;;
51 esac
52
53 case abc in ( [] ) echo yes ;; ( * ) echo no ;; esac
54 empty=''
55 case abc in ( ["$empty"] ) echo yes ;; ( * ) echo no ;; esac
56
57 case abc in ( [] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac
58 empty=''
59 case abc in ( ["$empty"] | [!a-z]* ) echo yes ;; ( * ) echo no ;; esac
60
61 case abc in (["$empty"]|[!a-z]*) echo yes ;; (*) echo no ;; esac
62
63 case " " in ( [" "] ) echo ok;; ( * ) echo no;; esac
64
65 # posix issue discovered after bash-5.1 was released
66 case esac in (esac) echo esac;; esac
67 case k in else|done|time|esac) for f in 1 2 3 ; do :; done esac
68
69 # tests of quote removal and pattern matching
70 ${THIS_SH} ./case1.sub
71 ${THIS_SH} ./case2.sub
72 ${THIS_SH} ./case3.sub
73 ${THIS_SH} ./case4.sub