about summary refs log tree commit diff
path: root/Test/B04read.ztst
blob: 14bdaeef5773a4952754a40ca21c947941cfa0b1 (plain) (blame)
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
121
122
# Tests for the read builtin

# Tested elsewhere:
#  reading from a coprocess  A01grammar, A04redirect

# Not tested:
#  -c/-l/-n (options for compctl functions)
#  -q/-s (needs a tty)

%test

 read <<<'hello world'
 print $REPLY
0:basic read command
>hello world

 read -A <<<'hello world'
 print $reply[2]
0:array read
>world

 read -k3 -u0 <<<foo:bar
 print $REPLY
0:read specified number of chars
>foo

 for char in y Y n N X $'\n'; do
   read -q -u0 <<<$char
   print $?
 done
0:read yes or no, default no
>0
>0
>1
>1
>1
>1

 read -d: <<<foo:bar
 print $REPLY
0:read up to delimiter
>foo

 print foo:bar|IFS=: read -A
 print $reply
0:use different, IFS separator to array
>foo bar

 print -z hello world; read -z
 print $REPLY
0:read from editor buffer stack
>hello world

 unset REPLY
 read -E <<<hello
 print $REPLY
0:read with echoing and assigning
>hello
>hello

 unset REPLY
 read -e <<<hello
 print $REPLY
0:read with echoing but assigning disabled
>hello
>

 read -e -t <<<hello
0:read with test first
>hello

 SECONDS=0
 read -e -t 5 <<<hello
 print $SECONDS
0:read with timeout (no waiting should occur)
>hello
>0

 print -n 'Testing the\0null hypothesis\0' |
 while read -d $'\0' line; do print $line; done
0:read with null delimiter
>Testing the
>null hypothesis

 read -ed '' <<<$'one\0two'
0:empty delimiter terminates at nulls
>one

 print -n $'first line\x80second line\x80' |
 while read -d $'\x80' line; do print $line; done
0:read with a delimiter >= 0x80
>first line
>second line

# Note that trailing NULLs are not stripped even if they are in
# $IFS; only whitespace characters contained in $IFS are stripped.
 print -n $'Aaargh, I hate nulls.\0\0\0' | read line
 print ${#line}
0:read with trailing metafied characters
>24

 (typeset -r foo
  read foo) <<<bar
1:return status on failing to set parameter
?(eval):2: read-only variable: foo

  read -AE array <<<'one two three'
  print ${(j.:.)array}
0:Behaviour of -A and -E combination
>one
>two
>three
>one:two:three

  array=()
  read -Ae array <<<'four five six'
  print ${(j.:.)array}
0:Behaviour of -A and -e combination
>four
>five
>six
>