2009-10-03 19:27:09 -04:00
|
|
|
USING: accessors continuations destructors io io.encodings
|
2009-11-12 19:36:20 -05:00
|
|
|
io.encodings.ascii io.encodings.binary
|
2009-10-03 19:27:09 -04:00
|
|
|
io.encodings.string io.encodings.utf8 io.files io.pipes
|
|
|
|
io.streams.byte-array io.streams.limited io.streams.string
|
2009-11-12 19:36:20 -05:00
|
|
|
kernel namespaces strings tools.test system
|
|
|
|
io.encodings.8-bit.latin1 ;
|
2009-01-19 19:52:09 -05:00
|
|
|
IN: io.streams.limited.tests
|
2008-06-12 04:50:20 -04:00
|
|
|
|
|
|
|
[ ] [
|
|
|
|
"hello world\nhow are you today\nthis is a very long line indeed"
|
|
|
|
ascii encode binary <byte-reader> "data" set
|
|
|
|
] unit-test
|
|
|
|
|
2010-07-09 14:30:57 -04:00
|
|
|
[ ] [ "data" get 24 <limited-stream> "limited" set ] unit-test
|
2008-06-12 04:50:20 -04:00
|
|
|
|
|
|
|
[ CHAR: h ] [ "limited" get stream-read1 ] unit-test
|
|
|
|
|
|
|
|
[ ] [ "limited" get ascii <decoder> "decoded" set ] unit-test
|
|
|
|
|
|
|
|
[ "ello world" ] [ "decoded" get stream-readln ] unit-test
|
|
|
|
|
|
|
|
[ "how " ] [ 4 "decoded" get stream-read ] unit-test
|
|
|
|
|
2010-07-09 14:30:57 -04:00
|
|
|
[ "are you " ] [ "decoded" get stream-readln ] unit-test
|
|
|
|
|
|
|
|
[ f ] [ "decoded" get stream-readln ] unit-test
|
|
|
|
|
2008-06-12 04:50:20 -04:00
|
|
|
|
|
|
|
[ ] [
|
|
|
|
"abc\ndef\nghi"
|
|
|
|
ascii encode binary <byte-reader> "data" set
|
|
|
|
] unit-test
|
|
|
|
|
2010-07-09 14:30:57 -04:00
|
|
|
[ ] [ "data" get 4 <limited-stream> "limited" set ] unit-test
|
2008-06-12 04:50:20 -04:00
|
|
|
|
2010-07-09 14:30:57 -04:00
|
|
|
[ "abc" CHAR: \n ]
|
|
|
|
[ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test
|
2008-06-12 04:50:20 -04:00
|
|
|
|
2010-07-09 14:30:57 -04:00
|
|
|
[ "" f ] [ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test
|
2008-06-17 01:10:09 -04:00
|
|
|
|
2009-01-19 19:19:12 -05:00
|
|
|
|
|
|
|
[ CHAR: a ]
|
2010-07-09 14:30:57 -04:00
|
|
|
[ "a" <string-reader> 1 <limited-stream> stream-read1 ] unit-test
|
2009-01-19 19:52:09 -05:00
|
|
|
|
|
|
|
[ "abc" ]
|
|
|
|
[
|
2010-07-09 14:30:57 -04:00
|
|
|
"abc" <string-reader> 3 <limited-stream>
|
2009-01-19 19:52:09 -05:00
|
|
|
4 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ]
|
|
|
|
[
|
2010-07-09 14:30:57 -04:00
|
|
|
"abc" <string-reader> 3 <limited-stream>
|
2009-01-19 19:52:09 -05:00
|
|
|
4 over stream-read drop 10 swap stream-read
|
|
|
|
] unit-test
|
2009-01-20 16:42:41 -05:00
|
|
|
|
2010-07-09 14:30:57 -04:00
|
|
|
! pipes are duplex and not seekable
|
2009-10-03 19:27:09 -04:00
|
|
|
[ "as" ] [
|
2010-07-09 14:30:57 -04:00
|
|
|
latin1 <pipe> [ 2 <limited-stream> ] change-in
|
2009-10-03 19:27:09 -04:00
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
2 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "as" ] [
|
2010-07-09 14:30:57 -04:00
|
|
|
latin1 <pipe> [ 2 <limited-stream> ] change-in
|
2009-10-03 19:27:09 -04:00
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
3 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! test seeking on limited unseekable streams
|
|
|
|
[ "as" ] [
|
2010-07-09 14:30:57 -04:00
|
|
|
latin1 <pipe> [ 2 <limited-stream> ] change-in
|
2009-10-03 19:27:09 -04:00
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
2 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "as" ] [
|
2010-07-09 14:30:57 -04:00
|
|
|
latin1 <pipe> [ 2 <limited-stream> ] change-in
|
2009-10-03 19:27:09 -04:00
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
3 swap stream-read
|
|
|
|
] unit-test
|
2010-09-08 03:49:04 -04:00
|
|
|
|
|
|
|
[ t ]
|
|
|
|
[
|
|
|
|
"abc" <string-reader> 3 limit-stream unlimit-stream
|
|
|
|
"abc" <string-reader> =
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ]
|
|
|
|
[
|
|
|
|
"abc" <string-reader> 3 limit-stream unlimit-stream
|
|
|
|
"abc" <string-reader> =
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ]
|
|
|
|
[
|
|
|
|
[
|
|
|
|
"resource:license.txt" utf8 <file-reader> &dispose
|
|
|
|
3 limit-stream unlimit-stream
|
|
|
|
"resource:license.txt" utf8 <file-reader> &dispose
|
|
|
|
[ decoder? ] both?
|
|
|
|
] with-destructors
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "asdf" ] [
|
|
|
|
"asdf" <string-reader> 2 <limited-stream> [
|
|
|
|
unlimited-input contents
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "asdf" ] [
|
|
|
|
"asdf" <string-reader> 2 <limited-stream> [
|
|
|
|
[ contents ] with-unlimited-input
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "gh" ] [
|
|
|
|
"asdfgh" <string-reader> 4 <limited-stream> [
|
|
|
|
2 [
|
|
|
|
[ contents drop ] with-unlimited-input
|
|
|
|
] with-limited-input
|
|
|
|
[ contents ] with-unlimited-input
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
2011-10-15 00:35:25 -04:00
|
|
|
|
|
|
|
{ 4 } [ B{ 0 1 2 3 4 5 } binary <byte-reader> 4 <limited-stream> stream-length ] unit-test
|
|
|
|
{ 6 } [ B{ 0 1 2 3 4 5 } binary <byte-reader> 8 <limited-stream> stream-length ] unit-test
|
|
|
|
|