2010-07-09 14:30:57 -04:00
|
|
|
! Copyright (C) 2010 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2011-10-15 00:35:25 -04:00
|
|
|
USING: destructors io io.encodings.binary io.encodings.utf8
|
|
|
|
io.files io.streams.byte-array io.streams.string
|
|
|
|
io.streams.throwing kernel namespaces tools.test ;
|
2010-07-09 14:30:57 -04:00
|
|
|
IN: io.streams.throwing.tests
|
|
|
|
|
2010-07-09 21:08:45 -04:00
|
|
|
[ "asdf" ]
|
2010-07-09 14:30:57 -04:00
|
|
|
[
|
2010-07-09 21:08:45 -04:00
|
|
|
"asdf" [ [ 6 read-partial ] throw-on-eof ] with-string-reader
|
2010-07-09 14:30:57 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
2010-07-09 21:08:45 -04:00
|
|
|
"asdf" [ [ 4 read read1 ] throw-on-eof ] with-string-reader
|
2010-07-09 14:30:57 -04:00
|
|
|
] [ stream-exhausted? ] must-fail-with
|
|
|
|
|
|
|
|
[
|
2010-07-09 21:08:45 -04:00
|
|
|
[
|
2010-09-27 21:20:48 -04:00
|
|
|
"asdf" <string-reader> [
|
|
|
|
4 read read1
|
2010-07-09 21:08:45 -04:00
|
|
|
] stream-throw-on-eof
|
|
|
|
] with-destructors
|
2010-07-09 14:30:57 -04:00
|
|
|
] [ stream-exhausted? ] must-fail-with
|
|
|
|
|
|
|
|
[
|
2010-07-09 21:08:45 -04:00
|
|
|
"asdf" [ [ 5 read ] throw-on-eof ] with-string-reader
|
2010-07-09 14:30:57 -04:00
|
|
|
] [ stream-exhausted? ] must-fail-with
|
|
|
|
|
|
|
|
[
|
2010-07-09 21:08:45 -04:00
|
|
|
"asdf" [ [ 4 read 4 read ] throw-on-eof ] with-string-reader
|
2010-07-09 14:30:57 -04:00
|
|
|
] [ stream-exhausted? ] must-fail-with
|
|
|
|
|
2010-07-09 21:08:45 -04:00
|
|
|
[ "as" "df" ] [
|
|
|
|
"asdf" [ [ 2 read ] throw-on-eof 3 read ] with-string-reader
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ "as" "df\n" ] [
|
|
|
|
"vocab:io/streams/throwing/asdf.txt" utf8 [
|
|
|
|
[ 2 read ] throw-on-eof 20 read
|
|
|
|
] with-file-reader
|
|
|
|
] unit-test
|
|
|
|
|
2011-10-15 00:35:25 -04:00
|
|
|
[ B{ 0 1 2 3 } B{ 0 1 2 3 } ] [
|
|
|
|
B{ 0 1 2 3 } binary [
|
2010-07-09 21:08:45 -04:00
|
|
|
[ 4 read 0 seek-absolute seek-input 4 read ] throw-on-eof
|
2011-10-15 00:35:25 -04:00
|
|
|
] with-byte-reader
|
2010-07-09 21:08:45 -04:00
|
|
|
] unit-test
|
2010-07-09 17:08:54 -04:00
|
|
|
|
|
|
|
[
|
2011-10-15 00:35:25 -04:00
|
|
|
B{ 0 1 2 3 } binary [
|
|
|
|
[ 1 seek-absolute seek-input 4 read drop ] throw-on-eof
|
|
|
|
] with-byte-reader
|
2010-07-09 17:08:54 -04:00
|
|
|
] [ stream-exhausted? ] must-fail-with
|
|
|
|
|
2010-07-09 17:26:01 -04:00
|
|
|
[ "asd" CHAR: f ] [
|
2010-07-09 21:08:45 -04:00
|
|
|
"asdf" [ [ "f" read-until ] throw-on-eof ] with-string-reader
|
2010-07-09 17:26:01 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
2010-07-09 21:08:45 -04:00
|
|
|
"asdf" [ [ "g" read-until ] throw-on-eof ] with-string-reader
|
2010-07-09 17:26:01 -04:00
|
|
|
] [ stream-exhausted? ] must-fail-with
|
|
|
|
|
2011-10-15 00:35:25 -04:00
|
|
|
{ 1 } [
|
|
|
|
B{ 0 1 2 3 } binary [
|
|
|
|
[ 1 seek-absolute seek-input tell-input ] throw-on-eof
|
|
|
|
] with-byte-reader
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
{ t 4 } [
|
|
|
|
B{ 0 1 2 3 } binary [ [
|
|
|
|
input-stream get [ stream-seekable? ] [ stream-length ] bi
|
|
|
|
] throw-on-eof ] with-byte-reader
|
2010-07-09 17:08:54 -04:00
|
|
|
] unit-test
|