USING: accessors continuations destructors io io.encodings io.encodings.ascii io.encodings.binary io.encodings.string io.encodings.utf8 io.files io.pipes io.streams.byte-array io.streams.limited io.streams.string kernel namespaces strings tools.test system io.encodings.8-bit.latin1 ; IN: io.streams.limited.tests [ ] [ "hello world\nhow are you today\nthis is a very long line indeed" ascii encode binary "data" set ] unit-test [ ] [ "data" get 24 "limited" set ] unit-test [ CHAR: h ] [ "limited" get stream-read1 ] unit-test [ ] [ "limited" get ascii "decoded" set ] unit-test [ "ello world" ] [ "decoded" get stream-readln ] unit-test [ "how " ] [ 4 "decoded" get stream-read ] unit-test [ "are you " ] [ "decoded" get stream-readln ] unit-test [ f ] [ "decoded" get stream-readln ] unit-test [ ] [ "abc\ndef\nghi" ascii encode binary "data" set ] unit-test [ ] [ "data" get 4 "limited" set ] unit-test [ "abc" CHAR: \n ] [ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test [ "" f ] [ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test [ CHAR: a ] [ "a" 1 stream-read1 ] unit-test [ "abc" ] [ "abc" 3 4 swap stream-read ] unit-test [ f ] [ "abc" 3 4 over stream-read drop 10 swap stream-read ] unit-test ! pipes are duplex and not seekable [ "as" ] [ latin1 [ 2 ] change-in "asdf" over stream-write dup stream-flush 2 swap stream-read ] unit-test [ "as" ] [ latin1 [ 2 ] change-in "asdf" over stream-write dup stream-flush 3 swap stream-read ] unit-test ! test seeking on limited unseekable streams [ "as" ] [ latin1 [ 2 ] change-in "asdf" over stream-write dup stream-flush 2 swap stream-read ] unit-test [ "as" ] [ latin1 [ 2 ] change-in "asdf" over stream-write dup stream-flush 3 swap stream-read ] unit-test [ t ] [ "abc" 3 limit-stream unlimit-stream "abc" = ] unit-test [ t ] [ "abc" 3 limit-stream unlimit-stream "abc" = ] unit-test [ t ] [ [ "resource:license.txt" utf8 &dispose 3 limit-stream unlimit-stream "resource:license.txt" utf8 &dispose [ decoder? ] both? ] with-destructors ] unit-test [ "asdf" ] [ "asdf" 2 [ unlimited-input contents ] with-input-stream ] unit-test [ "asdf" ] [ "asdf" 2 [ [ contents ] with-unlimited-input ] with-input-stream ] unit-test [ "gh" ] [ "asdfgh" 4 [ 2 [ [ contents drop ] with-unlimited-input ] with-limited-input [ contents ] with-unlimited-input ] with-input-stream ] unit-test { 4 } [ B{ 0 1 2 3 4 5 } binary 4 stream-length ] unit-test { 6 } [ B{ 0 1 2 3 4 5 } binary 8 stream-length ] unit-test