1# Tests for the read builtin
2
3# Tested elsewhere:
4#  reading from a coprocess  A01grammar, A04redirect
5
6# Not tested:
7#  -c/-l/-n (options for compctl functions)
8#  -q/-s (needs a tty)
9
10%test
11
12 read <<<'hello world'
13 print $REPLY
140:basic read command
15>hello world
16
17 read -A <<<'hello world'
18 print $reply[2]
190:array read
20>world
21
22 read -k3 -u0 <<<foo:bar
23 print $REPLY
240:read specified number of chars
25>foo
26
27 for char in y Y n N X $'\n'; do
28   read -q -u0 <<<$char
29   print $?
30 done
310:read yes or no, default no
32>0
33>0
34>1
35>1
36>1
37>1
38
39 read -d: <<<foo:bar
40 print $REPLY
410:read up to delimiter
42>foo
43
44 print foo:bar|IFS=: read -A
45 print $reply
460:use different, IFS separator to array
47>foo bar
48
49 print -z hello world; read -z
50 print $REPLY
510:read from editor buffer stack
52>hello world
53
54 unset REPLY
55 read -E <<<hello
56 print $REPLY
570:read with echoing and assigning
58>hello
59>hello
60
61 unset REPLY
62 read -e <<<hello
63 print $REPLY
640:read with echoing but assigning disabled
65>hello
66>
67
68 read -e -t <<<hello
690:read with test first
70>hello
71
72 SECONDS=0
73 read -e -t 5 <<<hello
74 print $SECONDS
750:read with timeout (no waiting should occur)
76>hello
77>0
78
79 print -n 'Testing the\0null hypothesis\0' |
80 while read -d $'\0' line; do print $line; done
810:read with null delimiter
82>Testing the
83>null hypothesis
84
85# Note that trailing NULLs are not stripped even if they are in
86# $IFS; only whitespace characters contained in $IFS are stripped.
87 print -n $'Aaargh, I hate nulls.\0\0\0' | read line
88 print ${#line}
890:read with trailing metafied characters
90>24
91
92 (typeset -r foo
93  read foo) <<<bar
941:return status on failing to set parameter
95?(eval):2: read-only variable: foo
96
97  read -AE array <<<'one two three'
98  print ${(j.:.)array}
990:Behaviour of -A and -E combination
100>one
101>two
102>three
103>one:two:three
104
105  array=()
106  read -Ae array <<<'four five six'
107  print ${(j.:.)array}
1080:Behaviour of -A and -e combination
109>four
110>five
111>six
112>
113