sh: Add tests for #/##/%/%% on $* and $@.
Although POSIX leaves things like ${*#X} unspecified, it occasionally occurs in practice. Add some tests that seem to work sensibly.
This commit is contained in:
parent
b5e81ea6b0
commit
cf1330bef9
@ -90,5 +90,6 @@ FILES+= trim5.0
|
||||
FILES+= trim6.0
|
||||
FILES+= trim7.0
|
||||
FILES+= trim8.0
|
||||
FILES+= trim9.0
|
||||
|
||||
.include <bsd.test.mk>
|
||||
|
61
bin/sh/tests/expansion/trim9.0
Normal file
61
bin/sh/tests/expansion/trim9.0
Normal file
@ -0,0 +1,61 @@
|
||||
# $FreeBSD$
|
||||
|
||||
# POSIX does not specify these but they occasionally occur in the wild.
|
||||
# This just serves to keep working what currently works.
|
||||
|
||||
failures=''
|
||||
ok=''
|
||||
|
||||
testcase() {
|
||||
code="$1"
|
||||
expected="$2"
|
||||
oIFS="$IFS"
|
||||
eval "$code"
|
||||
IFS='|'
|
||||
result="$#|$*"
|
||||
IFS="$oIFS"
|
||||
if [ "x$result" = "x$expected" ]; then
|
||||
ok=x$ok
|
||||
else
|
||||
failures=x$failures
|
||||
echo "For $code, expected $expected actual $result"
|
||||
fi
|
||||
}
|
||||
|
||||
testcase 'shift $#; set -- "${*#Q}"' '1|'
|
||||
testcase 'shift $#; set -- "${*##Q}"' '1|'
|
||||
testcase 'shift $#; set -- "${*%Q}"' '1|'
|
||||
testcase 'shift $#; set -- "${*%%Q}"' '1|'
|
||||
testcase 'set -- Q R; set -- "${*#Q}"' '1| R'
|
||||
testcase 'set -- Q R; set -- "${*##Q}"' '1| R'
|
||||
testcase 'set -- Q R; set -- "${*%R}"' '1|Q '
|
||||
testcase 'set -- Q R; set -- "${*%%R}"' '1|Q '
|
||||
testcase 'set -- Q R; set -- "${*#S}"' '1|Q R'
|
||||
testcase 'set -- Q R; set -- "${*##S}"' '1|Q R'
|
||||
testcase 'set -- Q R; set -- "${*%S}"' '1|Q R'
|
||||
testcase 'set -- Q R; set -- "${*%%S}"' '1|Q R'
|
||||
testcase 'set -- Q R; set -- ${*#Q}' '1|R'
|
||||
testcase 'set -- Q R; set -- ${*##Q}' '1|R'
|
||||
testcase 'set -- Q R; set -- ${*%R}' '1|Q'
|
||||
testcase 'set -- Q R; set -- ${*%%R}' '1|Q'
|
||||
testcase 'set -- Q R; set -- ${*#S}' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- ${*##S}' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- ${*%S}' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- ${*%%S}' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- ${@#Q}' '1|R'
|
||||
testcase 'set -- Q R; set -- ${@##Q}' '1|R'
|
||||
testcase 'set -- Q R; set -- ${@%R}' '1|Q'
|
||||
testcase 'set -- Q R; set -- ${@%%R}' '1|Q'
|
||||
testcase 'set -- Q R; set -- ${@#S}' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- ${@##S}' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- ${@%S}' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- ${@%%S}' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- "${@#Q}"' '2||R'
|
||||
testcase 'set -- Q R; set -- "${@%R}"' '2|Q|'
|
||||
testcase 'set -- Q R; set -- "${@%%R}"' '2|Q|'
|
||||
testcase 'set -- Q R; set -- "${@#S}"' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- "${@##S}"' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- "${@%S}"' '2|Q|R'
|
||||
testcase 'set -- Q R; set -- "${@%%S}"' '2|Q|R'
|
||||
|
||||
test "x$failures" = x
|
Loading…
Reference in New Issue
Block a user