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.
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.
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/>.
14 # A test suite for the POSIX.2 (BRE) pattern matching code
18 # First, test POSIX.2 character classes
21 [[:xdigit:]]) echo ok 1;;
25 [[:alpha:]123]) echo ok 2;;
29 [[:alpha:]123]) echo ok 3;;
33 [![:alpha:]]) echo ok 4;;
40 # invalid character class expressions are no longer just characters to be
48 [abc[:punct:][0-9]) echo ok 7;;
51 # let's try to match the start of a valid sh identifier
53 [_[:alpha:]]*) echo ok 8;;
56 # let's try to match the first two characters of a valid sh identifier
58 [_[:alpha:]][_[:alnum:]]*) echo ok 9;;
61 # is ^C a cntrl character?
63 [[:cntrl:]]) echo ok 10;;
68 [[:cntrl:]]) echo oops -- cntrl ;;
73 [[:digit:]]) echo ok 12;;
77 [[:digit:]]) echo oops -- digit;;
82 [[:graph:]]) echo oops -- graph;;
87 [[:graph:]]) echo oops -- graph 2;;
92 [[:graph:]]) echo oops -- graph 3;;
97 [[:lower:]][[:upper:]]) echo ok 17;;
101 [[:print:]]) echo ok 18;;
102 *) echo oops -- print;;
106 [_[:alpha:]][_[:alnum:]][_[:alnum:]]*) echo ok 19;;
110 [[:alpha:][:digit:]]) echo ok 20;;
111 *) echo oops - skip brackpat ;;
115 [[:alpha:]\]) echo oops -- dangling backslash in brackpat ;;
119 # what's a newline? is it a blank? a space?
121 [[:blank:]]) echo ok -- blank ;;
122 [[:space:]]) echo ok -- space ;;
123 *) echo oops newline ;;
126 # OK, what's a tab? is it a blank? a space?
128 [[:blank:]]) echo ok -- blank ;;
129 [[:space:]]) echo ok -- space ;;
130 *) echo oops newline ;;
133 # let's check out characters in the ASCII range
135 [[:ascii:]]) echo oops -- ascii\?;;
139 [1[:alpha:]123]) echo oops 1;;
142 # however, an unterminated brace expression containing a valid char class
143 # that matches had better fail
145 [[:alpha:]) echo oops 2;;
149 [[:graph:]]) echo oops 3;;
153 [[:print:]]) echo oops 4;;
157 [[:punct:]]) echo oops 5;;
160 # Next, test POSIX.2 collating symbols
167 [[.hyphen.]-9]) echo ok 2;;
171 [[.a.]-[.z.]]) echo ok 3;;
179 [[.space.]]) echo ok 5;;
183 [[.grave-accent.]]) echo oops - grave;;
188 [[.-.]-9]) echo ok 7;;
191 # an invalid collating symbol cannot be the first part of a range
193 [[.yyz.]-[.z.]]) echo oops - yyz;;
198 [[.yyz.][.a.]-z]) echo ok 9;;
201 # but when not part of a range is not an error
203 [[.yyz.][.a.]-[.z.]]) echo ok 10 ;;
207 [[.a.]-[.Z.]]) echo oops -- bad range ;;
212 [[.a.]-[.zz.]p]) echo ok 12;;
213 *) echo oops -- bad range 2;;
217 [[.aa.]-[.z.]p]) echo ok 13;;
218 *) echo oops -- bad range 3;;
222 [[.yyz.]cde]) echo ok 14;;
226 [[.cb.]a-Za]*) echo ok 15;;
230 [[.space.][.tab.][.newline.]]) echo ok 16;;
233 # and finally, test POSIX.2 equivalence classes
236 [[:alpha:]][[=b=]][[:ascii:]]) echo ok 1;;
240 [[:alpha:]][[=B=]][[:ascii:]]) echo oops -- =B=;;
245 [[=b=]) echo oops;; # an incomplete equiv class is just a string