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}[$Line]: "$@" 24 ((Errors++)) 25} 26 27integer Errors=0 28Command=${0##*/} 29 30# {...} expansion tests -- ignore if not supported 31 32[[ $(print a{0,1}z) == "a0z a1z" ]] || exit 0 33 34integer Line=$LINENO+1 35set -- \ 36 'ff{c,b,a}' 'ffc ffb ffa' \ 37 'f{d,e,f}g' 'fdg feg ffg' \ 38 '{l,n,m}xyz' 'lxyz nxyz mxyz' \ 39 '{abc\,def}' '{abc,def}' \ 40 '{abc}' '{abc}' \ 41 '\{a,b,c,d,e}' '{a,b,c,d,e}' \ 42 '{x,y,\{a,b,c}}' 'x} y} {a} b} c}' \ 43 '{x\,y,\{abc\},trie}' 'x,y {abc} trie' \ 44 '/usr/{ucb/{ex,edit},lib/{ex,how_ex}}' '/usr/ucb/ex /usr/ucb/edit /usr/lib/ex /usr/lib/how_ex' \ 45 'XXXX\{a,b,c\}' 'XXXX{a,b,c}' \ 46 '{}' '{}' \ 47 '{ }' '{ }' \ 48 '}' '}' \ 49 '{' '{' \ 50 'abcd{efgh' 'abcd{efgh' \ 51 'foo {1,2} bar' 'foo 1 2 bar' \ 52 '`print -r -- foo {1,2} bar`' 'foo 1 2 bar' \ 53 '$(print -r -- foo {1,2} bar)' 'foo 1 2 bar' \ 54 '{1..10}' '1 2 3 4 5 6 7 8 9 10' \ 55 '{0..10,braces}' '0..10 braces' \ 56 '{{0..10},braces}' '0 1 2 3 4 5 6 7 8 9 10 braces' \ 57 'x{{0..10},braces}y' 'x0y x1y x2y x3y x4y x5y x6y x7y x8y x9y x10y xbracesy' \ 58 '{3..3}' '3' \ 59 'x{3..3}y' 'x3y' \ 60 '{10..1}' '10 9 8 7 6 5 4 3 2 1' \ 61 '{10..1}y' '10y 9y 8y 7y 6y 5y 4y 3y 2y 1y' \ 62 'x{10..1}y' 'x10y x9y x8y x7y x6y x5y x4y x3y x2y x1y' \ 63 '{a..f}' 'a b c d e f' \ 64 '{f..a}' 'f e d c b a' \ 65 '{a..A}' '{a..A}' \ 66 '{A..a}' '{A..a}' \ 67 '{f..f}' 'f' \ 68 '{1..f}' '{1..f}' \ 69 '{f..1}' '{f..1}' \ 70 '0{1..9} {10..20}' '01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20' \ 71 '{-1..-10}' '-1 -2 -3 -4 -5 -6 -7 -8 -9 -10' \ 72 '{-19..0}' '-19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0' \ 73 '{0..10}' '0 1 2 3 4 5 6 7 8 9 10' \ 74 '{0..10..1}' '0 1 2 3 4 5 6 7 8 9 10' \ 75 '{0..10..2}' '0 2 4 6 8 10' \ 76 '{0..10..3}' '0 3 6 9' \ 77 '{0..10..0}' '{0..10..0}' \ 78 '{0..10..-1}' '0' \ 79 '{10..0}' '10 9 8 7 6 5 4 3 2 1 0' \ 80 '{10..0..-1}' '10 9 8 7 6 5 4 3 2 1 0' \ 81 '{10..0..-2}' '10 8 6 4 2 0' \ 82 '{10..0..-3}' '10 7 4 1' \ 83 '{10..0..0}' '{10..0..0}' \ 84 '{10..0..1}' '10' \ 85 '{a..z..2}' 'a c e g i k m o q s u w y' \ 86 '{y..b..-3}' 'y v s p m j g d' \ 87 '{0..0x1000..0x200}' '0 512 1024 1536 2048 2560 3072 3584 4096' \ 88 '{a,b}{0..2}{z,y}' 'a0z a0y a1z a1y a2z a2y b0z b0y b1z b1y b2z b2y' \ 89 '{0..0100..8%03o}' '000 010 020 030 040 050 060 070 100' \ 90 '{0..0100..040%020o}' '00000000000000000000 00000000000000000040 00000000000000000100' \ 91 '{0..7%03..2u}' '000 001 010 011 100 101 110 111' \ 92 '{0..10%llu}' '{0..10%llu}' \ 93 '{0..10%s}' '{0..10%s}' \ 94 '{0..10%dl}' '{0..10%dl}' \ 95 '{a,b}{0..3%02..2u}{y,z}' 'a00y a00z a01y a01z a10y a10z a11y a11z b00y b00z b01y b01z b10y b10z b11y b11z' \ 96 97while (($#>1)) 98do ((Line++)) 99 pattern=$1 100 shift 101 expected=$1 102 shift 103 got=$(eval print -r -- "$pattern") 104 [[ $got == $expected ]] || err_exit "'$pattern' failed -- expected '$expected' got '$got'" 105 #print -r -- " '$pattern' '$got' \\" 106done 107 108# ~(N) no expand glob pattern option 109set -- ~(N)/dev/null 110[[ $# == 1 && $1 == /dev/null ]] || err_exit "~(N)/dev/null not matching /dev/null" 111set -- ~(N)/dev/non_existant_file 112[[ $# == 0 ]] || err_exit "~(N)/dev/nonexistant not empty" 113set -- ""~(N)/dev/non_existant_file 114[[ $# == 1 && ! $1 ]] || err_exit '""~(N)/dev/nonexistant not null argument' 115set -- ~(N)/dev/non_existant_file"" 116[[ $# == 1 && ! $1 ]] || err_exit '~(N)/dev/nonexistent"" not null argument' 117for i in ~(N)/dev/non_existent_file 118do err_exit "~(N)/dev/non_existent_file in for loop is $i" 119done 120for i in ""~(N)/dev/non_existent_file 121do [[ ! $i ]] || err_exit '""~(N)/dev/non_existent_file not null' 122done 123exit $((Errors)) 124