########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
}
alias err_exit='err_exit $LINENO'
function test_glob
{
lineno=$1
shift
if [[ $1 == --* ]]
then del=${1#--}
shift
fi
if [[ $1 == ++* ]]
then add=${1#++}
shift
fi
expected=$1
shift
fi
fi
fi
for arg
sep=" "
done
then if [[ $del ]]
fi
if [[ $add ]]
fi
fi
fi
}
alias test_glob='test_glob $LINENO'
function test_case
{
eval "
case $subject in
$pattern) got='<match>' ;;
*) got='<nomatch>' ;;
esac
"
fi
}
alias test_case='test_case $LINENO'
unset undefined
export LC_COLLATE=C
touch B b
set -- *
case $* in
b|B) ignorant=1 ;;
esac
case $* in
B) aware=1 ;;
esac
test_glob '<a> <abc> <abd> <abe> <X*>' a* X*
test_glob '<a> <abc> <abd> <abe>' \a*
then
set --nullglob
test_glob '<a> <abc> <abd> <abe>' a* X*
set --nonullglob
fi
then
set --failglob
set --nofailglob
fi
test_glob '<bdir/>' b*/
test_glob '<*>' \*
test_glob '<a*>' 'a*'
test_glob '<a*>' a\*
test_glob '<c> <ca> <cb> <a*> <*q*>' c* a\* *q*
test_glob '<**>' \**
test_glob '<s/\..*//>' 's/\..*//'
test_glob '</^root:/{s/^[!:]*:[!:]*:\([!:]*\).*$/\1/>' "/^root:/{s/^[!:]*:[!:]*:\([!:]*\).*"'$'"/\1/"
test_glob '<abc> <abd> <abe> <bb> <cb>' [a-c]b*
test_glob '<abd> <abe>' a*[!c]
test_glob '<a-b> <aXb>' a[X-]b
touch .x .y
then
test_case '<match>' '!7' '*\!*'
test_case '<match>' 'r.*' '*.\*'
test_glob '<abc>' a[b]c
test_glob '<abc>' a[\b]c
test_glob '<abc>' a?c
test_case '<match>' 'abc' 'a"b"c'
test_case '<match>' 'abc' 'a*c'
test_case '<nomatch>' 'abc' '"a?c"'
test_case '<nomatch>' 'abc' 'a\*c'
test_case '<nomatch>' 'abc' 'a\[b]c'
test_case '<match>' '"$undefined"' '""'
test_case '<match>' 'abc' 'a["\b"]c'
fi
test_case '<match>' 'abc' 'a***c'
test_case '<match>' 'abc' 'a*****?c'
test_case '<match>' 'abc' '?*****??'
test_case '<match>' 'abc' '*****??'
test_case '<match>' 'abc' '*****??c'
test_case '<match>' 'abc' '?*****?c'
test_case '<match>' 'abc' '?***?****c'
test_case '<match>' 'abc' '?***?****?'
test_case '<match>' 'abc' '?***?****'
test_case '<match>' 'abc' '*******c'
test_case '<match>' 'abc' '*******?'
test_case '<match>' 'abcdecdhjk' 'a*cd**?**??k'
test_case '<match>' 'abcdecdhjk' 'a**?**cd**?**??k'
test_case '<match>' 'abcdecdhjk' 'a**?**cd**?**??k***'
test_case '<match>' 'abcdecdhjk' 'a**?**cd**?**??***k'
test_case '<match>' 'abcdecdhjk' 'a**?**cd**?**??***k**'
test_case '<match>' 'abcdecdhjk' 'a****c**?**??*****'
then
set --nocaseglob
set --nonocaseglob
fi
then
set -f
test_glob '<*>' *
set +f
fi
then
set --noglob
test_glob '<*>' *
set --glob
fi
FIGNORE='@(.*|*)'
test_glob '<*>' *
FIGNORE='@(.*|*c|*e|?)'
FIGNORE='@(.*|*b|*d|?)'
FIGNORE=
unset FIGNORE
GLOBIGNORE='.*:*'
set -- *
if [[ $1 == '*' ]]
then
GLOBIGNORE='.*:*c:*e:?'
test_glob '<>' *
GLOBIGNORE='.*:*b:*d:?'
test_glob '<>' *
unset GLOBIGNORE
test_glob '<>' *
GLOBIGNORE=
fi
unset GLOBIGNORE
function test_sub
{
eval g=$x
if [[ "$g" != "$3" ]]
fi
}
set --noglob --nobraceexpand
test_sub '/e/#' 'A r#gular expressions test'
test_sub '//e/#' 'A r#gular #xpr#ssions t#st'
test_sub '/[^e]/#' '# regular expressions test'
test_sub '//[^e]/#' '###e######e###e########e##'
test_sub '/+(e)/#' 'A r#gular expressions test'
test_sub '//+(e)/#' 'A r#gular #xpr#ssions t#st'
test_sub '/@-(e)/#' 'A r#gular expressions test'
test_sub '//@-(e)/#' 'A r#gular #xpr#ssions t#st'
test_sub '/?(e)/#' '#A regular expressions test'
test_sub '//?(e)/#' '#A# #r#g#u#l#a#r# #x#p#r#s#s#i#o#n#s# #t#s#t#'
test_sub '/*(e)/#' '#A regular expressions test'
test_sub '//*(e)/#' '#A# #r#g#u#l#a#r# #x#p#r#s#s#i#o#n#s# #t#s#t#'
test_sub '//@(e)/[\1]' 'A r[e]gular [e]xpr[e]ssions t[e]st'
test_sub '//@-(e)/[\1]' 'A r[e]gular [e]xpr[e]ssions t[e]st'
test_sub '//+(e)/[\1]' 'A r[e]gular [e]xpr[e]ssions t[e]st'
test_sub '//+-(e)/[\1]' 'A r[e]gular [e]xpr[e]ssions t[e]st'
test_sub '//@(+(e))/[\1]' 'A r[e]gular [e]xpr[e]ssions t[e]st'
test_sub '//@(+-(e))/[\1]' 'A r[e]gular [e]xpr[e]ssions t[e]st'
test_sub '//-(e)/#' 'A regular expressions test'
test_sub '//--(e)/#' 'A regular expressions test'
test_sub '//?(e)/[\1]' '[]A[] []r[e]g[]u[]l[]a[]r[] [e]x[]p[]r[e]s[]s[]i[]o[]n[]s[] []t[e]s[]t[]'
test_sub '//{0,1}(e)/[\1]' '[]A[] []r[e]g[]u[]l[]a[]r[] [e]x[]p[]r[e]s[]s[]i[]o[]n[]s[] []t[e]s[]t[]'
test_sub '//*(e)/[\1]' '[]A[] []r[e]g[]u[]l[]a[]r[] [e]x[]p[]r[e]s[]s[]i[]o[]n[]s[] []t[e]s[]t[]'
test_sub '//{0,}(e)/[\1]' '[]A[] []r[e]g[]u[]l[]a[]r[] [e]x[]p[]r[e]s[]s[]i[]o[]n[]s[] []t[e]s[]t[]'
test_sub '//@(?(e))/[\1]' '[]A[] []r[e]g[]u[]l[]a[]r[] [e]x[]p[]r[e]s[]s[]i[]o[]n[]s[] []t[e]s[]t[]'
test_sub '//@({0,1}(e))/[\1]' '[]A[] []r[e]g[]u[]l[]a[]r[] [e]x[]p[]r[e]s[]s[]i[]o[]n[]s[] []t[e]s[]t[]'
test_sub '//@(*(e))/[\1]' '[]A[] []r[e]g[]u[]l[]a[]r[] [e]x[]p[]r[e]s[]s[]i[]o[]n[]s[] []t[e]s[]t[]'
test_sub '//@({0,}(e))/[\1]' '[]A[] []r[e]g[]u[]l[]a[]r[] [e]x[]p[]r[e]s[]s[]i[]o[]n[]s[] []t[e]s[]t[]'
test_sub '/?-(e)/#' '#A regular expressions test'
test_sub '/@(?-(e))/[\1]' '[]A regular expressions test'
test_sub '/!(e)/#' '#'
test_sub '//!(e)/#' '#'
test_sub '/@(!(e))/[\1]' '[A regular expressions test]'
test_sub '//@(!(e))/[\1]' '[A regular expressions test]'
subject='e'
test_sub '/!(e)/#' '#e'
test_sub '//!(e)/#' '#e#'
test_sub '/!(e)/[\1]' '[]e'
test_sub '//!(e)/[\1]' '[]e[]'
test_sub '/@(!(e))/[\1]' '[]e'
test_sub '//@(!(e))/[\1]' '[]e[]'
subject='a'
test_sub '/@(!(a))/[\1]' '[]a'
test_sub '//@(!(a))/[\1]' '[]a[]'
subject='aha'
test_sub '/@(!(a))/[\1]' '[aha]'
test_sub '//@(!(a))/[\1]' '[aha]'
test_sub '/@(!(aha))/[\1]' '[ah]a'
test_sub '//@(!(aha))/[\1]' '[ah][a]'