-
Notifications
You must be signed in to change notification settings - Fork 138
/
parrotio.t
287 lines (233 loc) · 6.54 KB
/
parrotio.t
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!perl
# Copyright (C) 2006, The Perl Foundation.
# $Id$
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Test tests => 6;
=head1 NAME
t/pmc/parrotio.t - test the ParrotIO PMC
=head1 SYNOPSIS
% prove t/pmc/parrotio.t
=head1 DESCRIPTION
Tests the ParrotIO PMC.
=cut
# L<PDD22/I\/O PMC API/=item new>
pir_output_is( <<'CODE', <<'OUT', 'new' );
.sub 'test' :main
new P0, .ParrotIO
say 'ok 1 - $P0 = new .ParrotIO'
.end
CODE
ok 1 - $P0 = new .ParrotIO
OUT
# L<PDD22/I\/O PMC API/=item open.*=item close>
pir_output_is( <<'CODE', <<'OUT', 'open and close - synchronous', todo => 'not yet implemented' );
.sub 'test' :main
$P0 = new .ParrotIO
$P0.open('README')
say 'ok 1 - $P0.open($S1)'
$P0.close()
say 'ok 2 - $P0.close()'
$P0.open('README', 'rw')
say 'ok 3 - $P0.open($S1, $S2) # rw mode'
$P0.close()
$P0.open()
say 'ok 4 - $P0.open()'
push_eh eh_bad_file_1
$P0.open('bad_file')
clear_eh
test_5:
push_eh eh_bad_file_2
$P0.open('bad_file', 'r')
clear_eh
test_6:
$P0.open('new_file', 'w')
say 'ok 6 - $P0.open($S1, $S2) # new file, write mode succeeds'
goto end
bad_file_1:
say 'ok 5 - $P0.open($S1) # with bad file'
goto test_5
end:
.end
CODE
ok 1 - $P0.open($S1)
ok 2 - $P0.close()
ok 3 - $P0.open($S1, $S2) # rw mode
ok 4 - $P0.open()
ok 5 - $P0.open($S1) # with bad file
ok 6 - $P0.open($S1, $S2) # new file, write mode succeeds
OUT
# TODO test open file, close file, delete file, reopen previously opened stream
# TODO cleanup 'new_file'
SKIP: {
skip 'no asynch calls yet' => 1;
pir_output_is( <<'CODE', <<'OUT', 'open and close - asynchronous' );
.sub 'test' :main
$P1 = # TODO create a callback here
$P0 = new .ParrotIO
$P0.open('README')
say 'ok 1 - $P0.open($S1)'
$P0.close()
say 'ok 2 - $P0.close($P1)'
$P0.open('README', 'rw')
say 'ok 3 - $P0.open($S1, $S2)'
$P0.close()
$P0.open()
say 'ok 4 - $P0.open()'
cleanup:
$P0.close()
.end
CODE
ok 1 - $P0.open($S1)
ok 2 - $P0.close()
ok 3 - $P0.open($S1, $S2)
ok 4 - $P0.open()
OUT
}
# L<PDD22/I\/O PMC API/=item print.*=item readline>
pir_output_is(
<<'CODE', <<'OUT', 'print, read, and readline - synchronous', todo => 'not yet implemented' );
.sub 'test' :main
load_bytecode 'String/Utils.pbc'
.local pmc chomp
chomp = get_global ['String';'Utils'], 'chomp'
$P0 = new .ParrotIO
$P0.open('README')
$S0 = $P0.read(14) # bytes
if $S0 == 'This is Parrot' goto ok_1
print 'not '
ok_1:
say 'ok 1 - $S0 = $P1.read($I2)'
$S0 = $P0.read(9) # bytes
if $S0 == ', version' goto ok_2
print 'not '
ok_2:
say 'ok 2 - $S0 = $P1.read($I2) # again on same stream'
$P0.print(123)
$P0.print(456.789)
$P0.print("squawk\n")
$P1 = new .Integer
$P1 = 42
$P0.print($P1)
say 'ok 3 - $P0.print(${I,N,S,P}1)'
$S0 = $P0.readline()
$S0 = chomp( $S0 )
if $S0 == '123456.789000squawk' goto ok_4
print 'not '
ok_4:
say 'ok 4 - $S0 = $P1.readline($I2)'
$S0 = $P0.readline()
$S0 = chomp( $S0 )
if $S0 == '42' goto ok_5
print 'not '
ok_5:
say 'ok 5 - $S0 = $P1.readline($I2) # again on same stream'
.end
CODE
ok 1 - $S0 = $P1.read($I2)
ok 2 - $S0 = $P1.read($I2) # again on same stream
ok 3 - $P0.print(${I,N,S,P}1)
ok 4 - $S0 = $P1.readline($I2)
ok 5 - $S0 = $P1.readline($I2) # again on same stream
OUT
# TODO test reading/writing code points once supported
# TODO test reading long chunks, eof, and across newlines
# TODO pir_output_is( <<'CODE', <<'OUT', 'print, read, and readline - asynchronous', todo => 'not yet implemented' );
# L<PDD22/I\/O PMC API/=item record_separator>
pir_output_is( <<'CODE', <<'OUT', 'record_separator', todo => 'not yet implemented' );
.sub 'test' :main
$P0 = new .ParrotIO
$S0 = $P0.record_separator()
if $S0 == "\n" goto ok_1
print 'not '
ok_1:
say 'ok 1 - $S0 = $P1.record_separator() # default'
$S99 = 'abc'
$P0.record_separator($S99)
$S0 = $P0.record_separator()
if $S0 == $S99 goto ok_2
print 'not '
ok_2:
say 'ok 2 - $P0.record_separator($S1)'
$P0.print(123)
$S0 = $P0.record_separator()
$P0.print($S0)
$P0.print(456)
$S0 = $P0.readline()
if $S0 == '123abc' goto ok_3
print 'not '
ok_3:
say 'ok 3 - $P0.record_separator() # .readline works as expected'
.end
CODE
ok 1 - $S0 = $P1.record_separator() # default
ok 2 - $P0.record_separator($S1)
ok 3 - $P0.record_separator() # .readline works as expected
OUT
# L<PDD22/I\/O PMC API/=item buffer_type>
pir_output_is( <<'CODE', <<'OUT', 'buffer_type', todo => 'not yet implemented' );
.sub 'test' :main
.include 'io_buffer_types.pasm'
$P0 = new .ParrotIO
$P0.buffer_type('unbuffered')
$I0 = $P0.buffer_type()
if $I0 == PIO_NONBUF goto ok_1
print 'not '
ok_1:
say 'ok 1 - $I0 = $P1.buffer_type() # PIO_NONBUF'
$P0.buffer_type(PIO_NONBUF)
$S0 = $P0.buffer_type()
if $S0 == 'unbuffered' goto ok_2
print 'not '
ok_2:
say 'ok 2 - $S0 = $P1.buffer_type() # PIO_NONBUF'
$P0.buffer_type('line-buffered')
$I0 = $P0.buffer_type()
if $I0 == PIO_LINEBUF goto ok_3
print 'not '
ok_3:
say 'ok 3 - $I0 = $P1.buffer_type() # PIO_LINEBUF'
$P0.buffer_type(PIO_LINEBUF)
$S0 = $P0.buffer_type()
if $S0 == 'line-buffered' goto ok_4
print 'not '
ok_4:
say 'ok 4 - $S0 = $P1.buffer_type() # PIO_LINEBUF'
$P0.buffer_type('full-buffered')
$I0 = $P0.buffer_type()
if $I0 == PIO_FULLBUF goto ok_5
print 'not '
ok_5:
say 'ok 5 - $I0 = $P1.buffer_type() # PIO_FULLBUF'
$P0.buffer_type(PIO_FULLBUF)
$S0 = $P0.buffer_type()
if $S0 == 'full-buffered' goto ok_6
print 'not '
ok_6:
say 'ok 6 - $S0 = $P1.buffer_type() # PIO_FULLBUF'
.end
CODE
ok 1 - $I0 = $P1.buffer_type() # PIO_NONBUF
ok 2 - $S0 = $P1.buffer_type() # PIO_NONBUF
ok 3 - $I0 = $P1.buffer_type() # PIO_LINEBUF
ok 4 - $S0 = $P1.buffer_type() # PIO_LINEBUF
ok 5 - $I0 = $P1.buffer_type() # PIO_FULLBUF
ok 6 - $S0 = $P1.buffer_type() # PIO_FULLBUF
OUT
# TODO test effects of buffer_type, not just set/get
# TODO
# L<PDD22/I\/O PMC API/=item buffer_size>
# NOTES: try setting positive, zero, negative int
# perform print and read ops
# change buffer size while it contains data
# try with all 'buffer_type' modes
# L<PDD22/I\/O PMC API/=item get_fd>
# NOTES: this is going to be platform dependent
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: