This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
059stream.test
76 lines (66 loc) · 1.7 KB
/
059stream.test
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
(test "read works"
:valueof (making stdin (instring "34 35")
(read))
:should be '(34 35))
system "echo abc > _x"
(test "read works on fd"
:valueof (making stdin (infd+input_fd "_x")
(read))
:should be 'abc)
system "rm _x"
(test "multiple reads work"
:valueof (making stdin (instring "34
35")
(read)
(read))
:should be 35)
(test "read_byte works"
:valueof (with instring "ab"
(read_byte)
(read_byte))
:should be 98)
(test "read_byte stops at eof"
:valueof (with instring "abc"
(with outstring
(whilet c (read_byte)
(pr c))))
:should be "979899")
(test "read_line stops at eof"
:valueof (with instring "abc
def
"
(with outstring
(whilet line (read_line)
(prn line))))
:should be "abc
def
")
(test "with infile/outfile works"
:valueof (let f (tmpfile)
(before (system+join "rm " f)
(with outfile f
(prn 34))
(with infile f
(read))))
:should be 34)
(test "with stream macros clean up after themselves"
:valueof (let f (tmpfile)
(before (system+join "rm " f)
(with outfile f
(prn 34))
(num_bindings 'stdin)))
:should be 1)
(test "drain works"
:valueof (with instring "a b
c d
e"
(drain+read))
:should be '((a b) (c d) e))
(test "pr can print multiple args"
:valueof (with outstring
(pr 1 2 3))
:should be "123")
(test "pr returns first arg"
:valueof (between (bind stdout (outstring)) :and (close&unbind stdout)
(pr 1 2 3))
:should be 1)