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
|
|
|
|
|
2009-01-20 16:42:41 -05:00
|
|
|
[ ] [ "data" get 24 stream-throws <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
|
|
|
|
|
|
|
|
[ "decoded" get stream-readln ] [ limit-exceeded? ] must-fail-with
|
|
|
|
|
|
|
|
[ ] [
|
|
|
|
"abc\ndef\nghi"
|
|
|
|
ascii encode binary <byte-reader> "data" set
|
|
|
|
] unit-test
|
|
|
|
|
2009-01-20 16:42:41 -05:00
|
|
|
[ ] [ "data" get 7 stream-throws <limited-stream> "limited" set ] unit-test
|
2008-06-12 04:50:20 -04:00
|
|
|
|
|
|
|
[ "abc" CHAR: \n ] [ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test
|
|
|
|
|
|
|
|
[ "\n" "limited" get stream-read-until ] [ limit-exceeded? ] must-fail-with
|
2008-06-17 01:10:09 -04:00
|
|
|
|
|
|
|
[ "he" CHAR: l ] [
|
|
|
|
B{ CHAR: h CHAR: e CHAR: l CHAR: l CHAR: o }
|
|
|
|
ascii <byte-reader> [
|
2009-01-20 16:42:41 -05:00
|
|
|
5 stream-throws limit-input
|
2008-06-17 01:10:09 -04:00
|
|
|
"l" read-until
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
2009-01-19 19:19:12 -05:00
|
|
|
|
|
|
|
[ CHAR: a ]
|
2009-01-20 16:42:41 -05:00
|
|
|
[ "a" <string-reader> 1 stream-eofs <limited-stream> stream-read1 ] unit-test
|
2009-01-19 19:52:09 -05:00
|
|
|
|
|
|
|
[ "abc" ]
|
|
|
|
[
|
2009-01-20 16:42:41 -05:00
|
|
|
"abc" <string-reader> 3 stream-eofs <limited-stream>
|
2009-01-19 19:52:09 -05:00
|
|
|
4 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ f ]
|
|
|
|
[
|
2009-01-20 16:42:41 -05:00
|
|
|
"abc" <string-reader> 3 stream-eofs <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
|
|
|
|
|
|
|
[ t ]
|
|
|
|
[
|
2009-03-20 02:47:09 -04:00
|
|
|
"abc" <string-reader> 3 stream-eofs limit unlimited
|
2009-01-20 16:42:41 -05:00
|
|
|
"abc" <string-reader> =
|
|
|
|
] unit-test
|
2009-01-26 16:14:54 -05:00
|
|
|
|
|
|
|
[ t ]
|
|
|
|
[
|
2009-03-20 02:47:09 -04:00
|
|
|
"abc" <string-reader> 3 stream-eofs limit unlimited
|
2009-01-26 16:14:54 -05:00
|
|
|
"abc" <string-reader> =
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ]
|
|
|
|
[
|
|
|
|
[
|
|
|
|
"resource:license.txt" utf8 <file-reader> &dispose
|
2009-03-20 02:47:09 -04:00
|
|
|
3 stream-eofs limit unlimited
|
2009-01-26 16:14:54 -05:00
|
|
|
"resource:license.txt" utf8 <file-reader> &dispose
|
|
|
|
[ decoder? ] both?
|
|
|
|
] with-destructors
|
|
|
|
] unit-test
|
2009-04-07 05:11:56 -04:00
|
|
|
|
|
|
|
[ "HELL" ] [
|
|
|
|
"HELLO"
|
|
|
|
[ f stream-throws limit-input 4 read ]
|
|
|
|
with-string-reader
|
2009-09-28 16:51:40 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
|
|
[ "asdf" ] [
|
|
|
|
"asdf" <string-reader> 2 stream-eofs <limited-stream> [
|
|
|
|
unlimited-input contents
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
2009-10-03 19:27:09 -04:00
|
|
|
|
|
|
|
[ 4 ] [
|
|
|
|
"abcdefgh" <string-reader> 4 stream-throws <limited-stream> [
|
|
|
|
4 seek-relative seek-input tell-input
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
"abcdefgh" <string-reader> 4 stream-throws <limited-stream> [
|
|
|
|
4 seek-relative seek-input
|
|
|
|
4 read
|
|
|
|
] with-input-stream
|
|
|
|
] [
|
|
|
|
limit-exceeded?
|
|
|
|
] must-fail-with
|
|
|
|
|
|
|
|
[
|
|
|
|
"abcdefgh" <string-reader> 4 stream-throws <limited-stream> [
|
|
|
|
4 seek-relative seek-input
|
|
|
|
-2 seek-relative
|
|
|
|
2 read
|
|
|
|
] with-input-stream
|
|
|
|
] [
|
|
|
|
limit-exceeded?
|
|
|
|
] must-fail-with
|
|
|
|
|
|
|
|
[
|
|
|
|
"abcdefgh" <string-reader> [
|
|
|
|
4 seek-relative seek-input
|
|
|
|
2 stream-throws limit-input
|
|
|
|
-2 seek-relative seek-input
|
|
|
|
2 read
|
|
|
|
] with-input-stream
|
|
|
|
] [
|
|
|
|
limit-exceeded?
|
|
|
|
] must-fail-with
|
|
|
|
|
|
|
|
[ "ef" ] [
|
|
|
|
"abcdefgh" <string-reader> [
|
|
|
|
4 seek-relative seek-input
|
|
|
|
2 stream-throws limit-input
|
|
|
|
4 seek-absolute seek-input
|
|
|
|
2 read
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "ef" ] [
|
|
|
|
"abcdefgh" <string-reader> [
|
|
|
|
4 seek-absolute seek-input
|
|
|
|
2 stream-throws limit-input
|
|
|
|
2 seek-absolute seek-input
|
|
|
|
4 seek-absolute seek-input
|
|
|
|
2 read
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! stream-throws, pipes are duplex and not seekable
|
|
|
|
[ "as" ] [
|
|
|
|
latin1 <pipe> [ 2 stream-throws <limited-stream> ] change-in
|
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
2 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
latin1 <pipe> [ 2 stream-throws <limited-stream> ] change-in
|
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
3 swap stream-read
|
|
|
|
] [
|
|
|
|
limit-exceeded?
|
|
|
|
] must-fail-with
|
|
|
|
|
|
|
|
! stream-eofs, pipes are duplex and not seekable
|
|
|
|
[ "as" ] [
|
|
|
|
latin1 <pipe> [ 2 stream-eofs <limited-stream> ] change-in
|
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
2 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "as" ] [
|
|
|
|
latin1 <pipe> [ 2 stream-eofs <limited-stream> ] change-in
|
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
3 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
! test seeking on limited unseekable streams
|
|
|
|
[ "as" ] [
|
|
|
|
latin1 <pipe> [ 2 stream-eofs <limited-stream> ] change-in
|
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
2 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "as" ] [
|
|
|
|
latin1 <pipe> [ 2 stream-eofs <limited-stream> ] change-in
|
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
3 swap stream-read
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
latin1 <pipe> [ 2 stream-throws <limited-stream> ] change-in
|
|
|
|
2 seek-absolute rot in>> stream-seek
|
|
|
|
] must-fail
|
|
|
|
|
|
|
|
[
|
|
|
|
"as"
|
|
|
|
] [
|
|
|
|
latin1 <pipe> [ 2 stream-throws <limited-stream> ] change-in
|
|
|
|
"asdf" over stream-write dup stream-flush
|
|
|
|
[ 2 seek-absolute rot in>> stream-seek ] [ drop ] recover
|
|
|
|
2 swap stream-read
|
|
|
|
] unit-test
|
2009-10-03 20:33:54 -04:00
|
|
|
|
|
|
|
[ 7 ] [
|
|
|
|
image binary stream-throws <limited-file-reader> [
|
|
|
|
7 read drop
|
|
|
|
tell-input
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ 70000 ] [
|
|
|
|
image binary stream-throws <limited-file-reader> [
|
|
|
|
70000 read drop
|
|
|
|
tell-input
|
|
|
|
] with-input-stream
|
|
|
|
] unit-test
|