Add a few tests for the read built-in.

This commit is contained in:
stefanf 2009-03-22 22:14:46 +00:00
parent 7836b44d7b
commit 79a3bf3a75
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,25 @@
# $FreeBSD$
set -e
echo "1 2 3" | { read a; echo "x${a}x"; }
echo "1 2 3" | { read a b; echo "x${a}x${b}x"; }
echo "1 2 3" | { read a b c; echo "x${a}x${b}x${c}x"; }
echo "1 2 3" | { read a b c d; echo "x${a}x${b}x${c}x${d}x"; }
echo " 1 2 3 " | { read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 2 3 " | { IFS=$(printf ' \t\n') read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 2 3 " | { IFS= read a b; echo "x${a}x${b}x"; }
echo " 1,2 3 " | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; }
echo ", 2 ,3" | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 ,,3" | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 , , 3" | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 ,2 3," | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 ,2 3,," | { IFS=' ,' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1,2 3 " | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; }
echo ", 2 ,3" | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 ,,3" | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 , , 3" | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 ,2 3," | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; }
echo " 1 ,2 3,," | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; }

View File

@ -0,0 +1,19 @@
x1 2 3x
x1x2 3x
x1x2x3x
x1x2x3xx
x1x2x3x
x1x2x3x
x 1 2 3 xx
x1x2x3x
xx2x3x
x1xx3x
x1xx3x
x1x2x3x
x1x2x3,,x
x1x2x3x
xx2x3x
x1xx3x
x1xx3x
x1x2x3x
x1x2x3,,x