blob: 84f1b89b38fa4f276d27973fc7a23f223b8c078d (
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
(load "../common")
(push-after-load
(each ((file '#"test-file"))
(remove-path file)))
(file-put-buf "test-file" #b'e38182e38182e38182')
(with-stream (s (open-file "test-file"))
(mtest
(true s) t
(get-byte s) #xe3
(get-byte s) #x81
(unget-byte #x81 s) #x81
(unget-byte #xe3 s) #xe3
(get-char s) #\あ))
(with-stream (s (open-file "test-file"))
(mtest
(true s) t
(get-byte s) #xe3
(get-char s) #\xdc81
(get-byte s) #x82))
(file-put-buf "test-file" #b'e38122e38182e38182')
(with-stream (s (open-file "test-file"))
(let ((b (make-buf 256)))
(mtest
(true s) t
(get-char s) #\xdce3
(get-byte s) #x81
(fill-buf-adjust b 0 s) 7
b #b'22e38182e38182')))
(with-stream (s (open-file "test-file"))
(mtest
(true s) t
(unget-char #\a s) #\a
(get-byte s) :error
(unget-byte 42 s) :error
(get-char s) #\a
(unget-byte 42 s) 42
(get-byte s) 42
(get-byte s) #xe3))
(with-stream (s (open-file "test-file"))
(mtest
(true s) t
(unget-char #\a s) #\a
(unget-byte 42 s) :error
(get-char s) #\a
(unget-byte 42 s) 42
(get-byte s) 42
(get-byte s) #xe3))
(mtest
(unget-byte #x82) #x82
(unget-byte #x81) #x81
(unget-byte #xe3) #xe3
(get-char) #\x3042)
(with-in-string-byte-stream (s "ABCD")
(mtest
(unget-byte 3 s) :error
(get-char s) #\A
(get-byte s) 66
(get-char s) #\C
(seek-stream s 0 :from-current) 3
(unget-char #\x3042 s) #\x3042
(seek-stream s 0 :from-current) 0
(get-char s) #\x3042
(unget-char #\x3042 s) #\x3042
(get-byte s) #xe3
(get-char s) #\xdc81
(seek-stream s 0 :from-current) 2
(unget-char #\x3042 s) :error
(seek-stream s -1 :from-start) :error
(seek-stream s 0 :from-start) t
(seek-stream s 0 :from-end) t
(seek-stream s 0 :from-current) 4
(seek-stream s 1 :from-end) :error
(seek-stream s -1 :from-end) t
(seek-stream s 0 :from-current) 3
(seek-stream s -4 :from-end) t
(seek-stream s 0 :from-current) 0
(seek-stream s -5 :from-end) :error))
(with-in-string-byte-stream (s "[1][foo]")
(mtest
(get-json s) #(1.0)
(get-string s) "[foo]"))
(with-in-string-byte-stream (s "[1]foo:(1 2 3)x")
(mtest
(get-json s) #(1.0)
(read-until-match #/:/ s t) "foo:"
(iread s) (1 2 3)
(get-char s) #\x))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s 3 #\:) "abc"
(get-string s) "d:"))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s 4 #\:) "abcd"
(get-string s) ":"))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s 5 #\:) "abcd"
(get-string s) ""))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s) "abcd:"
(get-string s) ""))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s 3) "abc"
(get-string s) "d:"))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s 4) "abcd"
(get-string s) ":"))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s 5) "abcd:"
(get-string s) ""))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s 6) "abcd:"
(get-string s) ""))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s) "abcd:"
(get-string s) ""))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s : #\:) "abcd"
(get-string s) ""))
(with-in-string-stream (s "abcd:")
(mtest
(get-delimited-string s : #\a) ""
(get-string s) "bcd:"))
(with-in-string-stream (s "abcde")
(mtest
(truncate-stream s 3) :error
(seek-stream s 10 :from-start) :error
(seek-stream s 6 :from-start) :error
(seek-stream s 5 :from-start) t
(get-char s) nil
(seek-stream s 3 :from-start) t
(get-char s) #\d
(seek-stream s 0 :from-start) t
(seek-stream s 0 :from-current) 0
(get-char s) #\a
(seek-stream s 0 :from-current) 1
(seek-stream s -1 :from-start) :error
(get-char s) #\b
(seek-stream s 0 :from-current) 2
(seek-stream s -2 :from-current) t
(seek-stream s 0 :from-current) 0
(get-char s) #\a
(seek-stream s -2 :from-current) :error
(seek-stream s 6 :from-current) :error
(seek-stream s -1 :from-end) t
(seek-stream s 6 :from-end) :error
(seek-stream s 1 :from-end) :error
(get-char s) #\e))
(with-out-string-stream (s)
(mtest
(truncate-stream s 8) t
(get-string-from-stream s t) " "
(truncate-stream s 5) t
(get-string-from-stream s t) " "
(seek-stream s 8 :from-start) t
(get-string-from-stream s t) " "
(seek-stream s -1 :from-start) :error
(seek-stream s -10 :from-end) :error
(seek-stream s 6 :from-start) t
(put-char #\6 s) t
(get-string-from-stream s t) " 6 "
(seek-stream s -8 :from-end) t
(put-char #\0 s) t
(get-string-from-stream s t) "0 6 "
(seek-stream s 0 :from-current) 1
(seek-stream s -1 :from-current) t
(put-char #\A s) t
(get-string-from-stream s t) "A 6 "
(put-string "BCDEF" s) t
(get-string-from-stream s t) "ABCDEF6 "
(put-string "GHI" s) t
(get-string-from-stream s) "ABCDEFGHI"
(get-string-from-stream s) nil
(truncate-stream s 2) :error
(seek-stream s 0 :from-current) :error
(put-string "X" s) :error))
(with-in-buf-stream (s (make-buf 16))
(mtest
(put-char #\A s) t
(get-buf-from-stream s) #b'41000000000000000000000000000000'
(put-string "BCD" s) t
(get-buf-from-stream s) #b'41424344000000000000000000000000'
(truncate-stream s -1) :error
(seek-stream s -1 :from-start) :error
(seek-stream s 0 :from-start) t
(put-char #\X s) t
(get-buf-from-stream s) #b'58424344000000000000000000000000'
(put-buf #b'AABBCCDDEEFF11' 0 s) 7
(get-buf-from-stream s) #b'58AABBCCDDEEFF110000000000000000'
(put-buf #b'AABBCCDDEEFF1122' 0 s) 8
(get-buf-from-stream s) #b'58AABBCCDDEEFF11AABBCCDDEEFF1122'
(truncate-stream s 16) t
(get-buf-from-stream s) #b'58AABBCCDDEEFF11AABBCCDDEEFF1122'
(truncate-stream s 18) t
(get-buf-from-stream s) #b'58AABBCCDDEEFF11AABBCCDDEEFF11220000'
(truncate-stream s 8) t
(get-buf-from-stream s) #b'58AABBCCDDEEFF110000000000000000'
(seek-stream s 0 :from-current) 16
(truncate-stream s 0) t
(get-buf-from-stream s) #b'00000000000000000000000000000000'
(seek-stream s -16 :from-end) t
(seek-stream s 0 :from-current) 0
(truncate-stream s 0) t
(get-buf-from-stream s) #b''))
(with-in-buf-stream (s #b'00112233445566778899AABCCCDDEEFF')
(let ((b (make-buf 0)))
(mtest
(fill-buf-adjust b 0 s) 0
b #b''
(seek-stream s 0 :from-current) 0
(buf-set-length b 5) 0
(fill-buf-adjust b 0 s) 5
b #b'0011223344'
(seek-stream s -3 :from-end) t
(fill-buf-adjust b 0 s) 3
b #b'DDEEFF')))
(with-in-buf-stream (s (buf-str "ABCD"))
(mtest
(seek-stream s 0 :from-start) t
(unget-byte 3 s) :error
(get-char s) #\A
(get-byte s) 66
(get-char s) #\C
(seek-stream s 0 :from-current) 3
(unget-char #\x3042 s) #\x3042
(seek-stream s 0 :from-current) 0
(get-char s) #\x3042
(unget-char #\x3042 s) #\x3042
(get-byte s) #xe3
(get-char s) #\xdc81
(seek-stream s 0 :from-current) 2
(unget-char #\x3042 s) :error))
|