1 USING: accessors io io.streams.string kernel math namespaces
2 parser sbufs sequences strings tools.test words ;
6 "vocab:io/test/no-trailing-eol.factor" run-file
7 "foo" "io.tests" lookup-word
10 ! Make sure we use correct to_c_string form when writing
11 { } [ "\0" write ] unit-test
13 ! Test default input stream protocol methods
15 TUPLE: up-to-13-reader { i fixnum initial: 0 } ;
16 INSTANCE: up-to-13-reader input-stream
18 M: up-to-13-reader stream-element-type drop +byte+ ; inline
19 M: up-to-13-reader stream-read1
20 [ dup 1 + ] change-i drop
21 dup 13 >= [ drop f ] when ; inline
23 { B{ 0 1 2 } } [ 3 up-to-13-reader new stream-read ] unit-test
24 { B{ 0 1 2 } } [ 3 up-to-13-reader new stream-read-partial ] unit-test
26 { B{ 0 1 2 3 4 5 6 7 8 9 10 11 12 } f }
27 [ up-to-13-reader new [ 20 swap stream-read ] [ 20 swap stream-read ] bi ] unit-test
30 T{ slice f 0 8 B{ 0 1 2 3 4 5 6 7 } } t
31 T{ slice f 0 5 B{ 8 9 10 11 12 205 206 207 } } t
32 T{ slice f 0 0 B{ 8 9 10 11 12 205 206 207 } } f
35 [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ]
36 [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ]
37 [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ] tri
41 B{ 0 1 2 3 4 5 6 7 8 } 9
46 [ "\t" swap stream-read-until ]
47 [ "\t" swap stream-read-until ]
48 [ "\t" swap stream-read-until ] tri
51 { B{ 0 1 2 3 4 5 6 7 8 9 } B{ 11 12 } f } [
53 [ stream-readln ] [ stream-readln ] [ stream-readln ] tri
56 ! Test default output stream protocol methods
58 TUPLE: dumb-writer vector ;
59 INSTANCE: dumb-writer output-stream
61 : <dumb-writer> ( -- x ) BV{ } clone dumb-writer boa ; inline
63 M: dumb-writer stream-element-type drop +byte+ ; inline
64 M: dumb-writer stream-write1 vector>> push ; inline
68 [ B{ 11 22 33 } swap stream-write ]
72 { BV{ 11 22 33 10 } } [
74 [ B{ 11 22 33 } swap stream-write ]
80 [ "asdf" <string-reader> 4 <sbuf> [ stream-copy ] keep ] unit-test
85 [ "asdf" error-stream get stream-write ] with-error>output
93 [ "asdf" output-stream get stream-write ] with-output>error