aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/read.in
blob: 893797a1b732440936120256c3de67c89df6f617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# vim: set filetype=fish:
#
# Test read builtin and IFS
#

count (echo one\ntwo)
set -l IFS \t
count (echo one\ntwo)
set -l IFS
count (echo one\ntwo)
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)]
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
echo 'foo   bar   baz' | read -l one two three
print_vars one two three
echo -n 'a' | read -l one
echo "$status $one"

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

# 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

# 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

true