2014-09-22 02:18:56 +00:00
|
|
|
# vim: set filetype=fish:
|
2014-07-14 05:36:26 +00:00
|
|
|
#
|
|
|
|
# Test read builtin and IFS
|
|
|
|
#
|
|
|
|
|
|
|
|
count (echo one\ntwo)
|
|
|
|
set -l IFS \t
|
|
|
|
count (echo one\ntwo)
|
|
|
|
set -l IFS
|
|
|
|
count (echo one\ntwo)
|
2014-08-29 01:27:23 +00:00
|
|
|
echo [(echo -n one\ntwo)]
|
|
|
|
count (echo one\ntwo\n)
|
|
|
|
echo [(echo -n one\ntwo\n)]
|
|
|
|
count (echo one\ntwo\n\n)
|
|
|
|
echo [(echo -n one\ntwo\n\n)]
|
2014-07-14 05:36:26 +00:00
|
|
|
set -le IFS
|
|
|
|
|
|
|
|
function print_vars --no-scope-shadowing
|
|
|
|
set -l space
|
|
|
|
set -l IFS \n # ensure our command substitution works right
|
|
|
|
for var in $argv
|
|
|
|
echo -n $space (count $$var) \'$$var\'
|
|
|
|
set space ''
|
|
|
|
end
|
|
|
|
echo
|
|
|
|
end
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo 'hello there' | read -l one two
|
|
|
|
print_vars one two
|
|
|
|
echo 'hello there' | read -l one
|
|
|
|
print_vars one
|
|
|
|
echo '' | read -l one
|
|
|
|
print_vars one
|
|
|
|
echo '' | read -l one two
|
|
|
|
print_vars one two
|
|
|
|
echo 'test' | read -l one two three
|
|
|
|
print_vars one two three
|
2014-09-22 02:18:56 +00:00
|
|
|
echo 'foo bar baz' | read -l one two three
|
|
|
|
print_vars one two three
|
2014-09-22 03:00:26 +00:00
|
|
|
echo -n 'a' | read -l one
|
|
|
|
echo "$status $one"
|
2014-07-14 05:36:26 +00:00
|
|
|
|
|
|
|
echo
|
|
|
|
set -l IFS
|
|
|
|
echo 'hello' | read -l one
|
|
|
|
print_vars one
|
|
|
|
echo 'hello' | read -l one two
|
|
|
|
print_vars one two
|
|
|
|
echo 'hello' | read -l one two three
|
|
|
|
print_vars one two three
|
|
|
|
echo '' | read -l one
|
|
|
|
print_vars one
|
|
|
|
echo 't' | read -l one two
|
|
|
|
print_vars one two
|
|
|
|
echo 't' | read -l one two three
|
|
|
|
print_vars one two three
|
|
|
|
echo ' t' | read -l one two
|
|
|
|
print_vars one two
|
|
|
|
set -le IFS
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo 'hello there' | read -la ary
|
|
|
|
print_vars ary
|
|
|
|
echo 'hello' | read -la ary
|
|
|
|
print_vars ary
|
|
|
|
echo 'this is a bunch of words' | read -la ary
|
|
|
|
print_vars ary
|
|
|
|
echo ' one two three' | read -la ary
|
|
|
|
print_vars ary
|
|
|
|
echo '' | read -la ary
|
|
|
|
print_vars ary
|
|
|
|
|
|
|
|
echo
|
|
|
|
set -l IFS
|
|
|
|
echo 'hello' | read -la ary
|
|
|
|
print_vars ary
|
|
|
|
echo 'h' | read -la ary
|
|
|
|
print_vars ary
|
|
|
|
echo '' | read -la ary
|
|
|
|
print_vars ary
|
|
|
|
set -le IFS
|
2014-08-19 12:28:08 +00:00
|
|
|
|
|
|
|
# read -n tests
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo '# read -n tests'
|
|
|
|
echo 'testing' | read -n 3 foo
|
|
|
|
echo $foo
|
|
|
|
echo 'test' | read -n 10 foo
|
|
|
|
echo $foo
|
|
|
|
echo 'test' | read -n 0 foo
|
|
|
|
echo $foo
|
|
|
|
echo 'testing' | begin; read -n 3 foo; read -n 3 bar; end
|
|
|
|
echo $foo
|
|
|
|
echo $bar
|
|
|
|
echo 'test' | read -n 1 foo
|
|
|
|
echo $foo
|
2014-09-22 02:18:56 +00:00
|
|
|
|
|
|
|
# read -0 tests
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo '# read -z tests'
|
|
|
|
echo -n 'testing' | read -lz foo
|
|
|
|
echo $foo
|
|
|
|
echo -n 'test ing' | read -lz foo
|
|
|
|
echo $foo
|
|
|
|
echo 'newline' | read -lz foo
|
|
|
|
echo $foo
|
|
|
|
echo -n 'test ing' | read -lz foo bar
|
|
|
|
print_vars foo bar
|
|
|
|
echo -ne 'test\0ing' | read -lz foo bar
|
|
|
|
print_vars foo bar
|
|
|
|
echo -ne 'foo\nbar' | read -lz foo bar
|
|
|
|
print_vars foo bar
|
|
|
|
echo -ne 'foo\nbar\0baz\nquux' | while read -lza foo
|
|
|
|
print_vars foo
|
|
|
|
end
|
|
|
|
|
2017-01-21 20:43:20 +00:00
|
|
|
echo
|
|
|
|
echo '# chunked read tests'
|
|
|
|
set -l path /tmp/fish_chunked_read_test.txt
|
|
|
|
set -l longstr (seq 1024 | string join ',')
|
|
|
|
echo -n $longstr > $path
|
|
|
|
read -l longstr2 < $path
|
|
|
|
test "$longstr" = "$longstr2"
|
|
|
|
and echo "Chunked reads test pass"
|
|
|
|
or echo "Chunked reads test failure: long strings don't match!"
|
2017-01-21 20:47:05 +00:00
|
|
|
rm $path
|
2017-01-21 20:43:20 +00:00
|
|
|
|
2014-09-22 02:18:56 +00:00
|
|
|
true
|