]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/throwing/throwing-tests.factor
more test IN: cleanup.
[factor.git] / basis / io / streams / throwing / throwing-tests.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: destructors io io.encodings.binary io.encodings.utf8
4 io.files io.streams.byte-array io.streams.string
5 io.streams.throwing kernel namespaces tools.test ;
6
7 { "asdf" }
8 [
9     "asdf" [ [ 6 read-partial ] throw-on-eof ] with-string-reader
10 ] unit-test
11
12 [
13     "asdf" [ [ 4 read read1 ] throw-on-eof ] with-string-reader
14 ] [ stream-exhausted? ] must-fail-with
15
16 [
17     [
18         "asdf" <string-reader> [
19             4 read read1
20         ] stream-throw-on-eof
21     ] with-destructors
22 ] [ stream-exhausted? ] must-fail-with
23
24 [
25     "asdf" [ [ 5 read ] throw-on-eof ] with-string-reader
26 ] [ stream-exhausted? ] must-fail-with
27
28 [
29     "asdf" [ [ 4 read 4 read ] throw-on-eof ] with-string-reader
30 ] [ stream-exhausted? ] must-fail-with
31
32 { "as" "df" } [
33     "asdf" [ [ 2 read ] throw-on-eof 3 read ] with-string-reader
34 ] unit-test
35
36 { "as" "df\n" } [
37     "vocab:io/streams/throwing/asdf.txt" utf8 [
38         [ 2 read ] throw-on-eof 20 read
39     ] with-file-reader
40 ] unit-test
41
42 { B{ 0 1 2 3 } B{ 0 1 2 3 } } [
43     B{ 0 1 2 3 } binary [
44         [ 4 read 0 seek-absolute seek-input 4 read ] throw-on-eof
45     ] with-byte-reader
46 ] unit-test
47
48 [
49     B{ 0 1 2 3 } binary [
50         [ 1 seek-absolute seek-input 4 read drop ] throw-on-eof
51     ] with-byte-reader
52 ] [ stream-exhausted? ] must-fail-with
53
54 { "asd" CHAR: f } [
55     "asdf" [ [ "f" read-until ] throw-on-eof ] with-string-reader
56 ] unit-test
57
58 [
59     "asdf" [ [ "g" read-until ] throw-on-eof ] with-string-reader
60 ] [ stream-exhausted? ] must-fail-with
61
62 { 1 } [
63     B{ 0 1 2 3 } binary [
64         [ 1 seek-absolute seek-input tell-input ] throw-on-eof
65     ] with-byte-reader
66 ] unit-test
67
68 { t 4 } [
69     B{ 0 1 2 3 } binary [ [
70         input-stream get [ stream-seekable? ] [ stream-length ] bi
71     ] throw-on-eof ] with-byte-reader
72 ] unit-test