]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/limited/limited-tests.factor
Merge branch 'master' into experimental
[factor.git] / basis / io / streams / limited / limited-tests.factor
1 USING: io io.streams.limited io.encodings io.encodings.string
2 io.encodings.ascii io.encodings.binary io.streams.byte-array
3 namespaces tools.test strings kernel io.streams.string accessors
4 io.encodings.utf8 io.files destructors ;
5 IN: io.streams.limited.tests
6
7 [ ] [
8     "hello world\nhow are you today\nthis is a very long line indeed"
9     ascii encode binary <byte-reader> "data" set
10 ] unit-test
11
12 [ ] [ "data" get 24 stream-throws <limited-stream> "limited" set ] unit-test
13
14 [ CHAR: h ] [ "limited" get stream-read1 ] unit-test
15
16 [ ] [ "limited" get ascii <decoder> "decoded" set ] unit-test
17
18 [ "ello world" ] [ "decoded" get stream-readln ] unit-test
19
20 [ "how " ] [ 4 "decoded" get stream-read ] unit-test
21
22 [ "decoded" get stream-readln ] [ limit-exceeded? ] must-fail-with
23
24 [ ] [
25     "abc\ndef\nghi"
26     ascii encode binary <byte-reader> "data" set
27 ] unit-test
28
29 [ ] [ "data" get 7 stream-throws <limited-stream> "limited" set ] unit-test
30
31 [ "abc" CHAR: \n ] [ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test
32
33 [ "\n" "limited" get stream-read-until ] [ limit-exceeded? ] must-fail-with
34
35 [ "he" CHAR: l ] [
36     B{ CHAR: h CHAR: e CHAR: l CHAR: l CHAR: o }
37     ascii <byte-reader> [
38         5 stream-throws limit-input
39         "l" read-until
40     ] with-input-stream
41 ] unit-test
42
43 [ CHAR: a ]
44 [ "a" <string-reader> 1 stream-eofs <limited-stream> stream-read1 ] unit-test
45
46 [ "abc" ]
47 [
48     "abc" <string-reader> 3 stream-eofs <limited-stream>
49     4 swap stream-read
50 ] unit-test
51
52 [ f ]
53 [
54     "abc" <string-reader> 3 stream-eofs <limited-stream>
55     4 over stream-read drop 10 swap stream-read
56 ] unit-test
57
58 [ t ]
59 [
60     "abc" <string-reader> 3 stream-eofs limit unlimit
61     "abc" <string-reader> =
62 ] unit-test
63
64 [ t ]
65 [
66     "abc" <string-reader> 3 stream-eofs limit unlimit
67     "abc" <string-reader> =
68 ] unit-test
69
70 [ t ]
71 [
72     [
73         "resource:license.txt" utf8 <file-reader> &dispose
74         3 stream-eofs limit unlimit
75         "resource:license.txt" utf8 <file-reader> &dispose
76         [ decoder? ] both?
77     ] with-destructors
78 ] unit-test