]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/limited/limited-tests.factor
factor: rename [ ] [ ] unit-test -> { } [ ] unit-test using a refactoring tool!
[factor.git] / basis / io / streams / limited / limited-tests.factor
1 USING: accessors continuations destructors io io.encodings
2 io.encodings.ascii io.encodings.binary
3 io.encodings.string io.encodings.utf8 io.files io.pipes
4 io.streams.byte-array io.streams.duplex io.streams.limited io.streams.string
5 kernel namespaces strings tools.test system
6 io.encodings.8-bit.latin1 ;
7 IN: io.streams.limited.tests
8
9 { } [
10     "hello world\nhow are you today\nthis is a very long line indeed"
11     ascii encode binary <byte-reader> "data" set
12 ] unit-test
13
14 { } [ "data" get 24 <limited-stream> "limited" set ] unit-test
15
16 { CHAR: h } [ "limited" get stream-read1 ] unit-test
17
18 { } [ "limited" get ascii <decoder> "decoded" set ] unit-test
19
20 { "ello world" } [ "decoded" get stream-readln ] unit-test
21
22 { "how " } [ 4 "decoded" get stream-read ] unit-test
23
24 { "are you " } [ "decoded" get stream-readln ] unit-test
25
26 { f } [ "decoded" get stream-readln ] unit-test
27
28
29 { } [
30     "abc\ndef\nghi"
31     ascii encode binary <byte-reader> "data" set
32 ] unit-test
33
34 { } [ "data" get 4 <limited-stream> "limited" set ] unit-test
35
36 { "abc" CHAR: \n }
37 [ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test
38
39 { "" f } [ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test
40
41
42 { CHAR: a }
43 [ "a" <string-reader> 1 <limited-stream> stream-read1 ] unit-test
44
45 { "abc" }
46 [
47     "abc" <string-reader> 3 <limited-stream>
48     4 swap stream-read
49 ] unit-test
50
51 { f }
52 [
53     "abc" <string-reader> 3 <limited-stream>
54     4 over stream-read drop 10 swap stream-read
55 ] unit-test
56
57 ! pipes are duplex and not seekable
58 { "as" } [
59     latin1 <pipe> [
60         input-stream [ 2 <limited-stream> ] change
61         "asdf" write flush 2 read
62     ] with-stream
63 ] unit-test
64
65 { "as" } [
66     latin1 <pipe> [
67         input-stream [ 2 <limited-stream> ] change
68         "asdf" write flush 3 read
69     ] with-stream
70 ] unit-test
71
72 ! test seeking on limited unseekable streams
73 { "as" } [
74     latin1 <pipe> [
75         input-stream [ 2 <limited-stream> ] change
76         "asdf" write flush 2 read
77     ] with-stream
78 ] unit-test
79
80 { "as" } [
81     latin1 <pipe> [
82         input-stream [ 2 <limited-stream> ] change
83         "asdf" write flush 3 read
84     ] with-stream
85 ] unit-test
86
87 { t }
88 [
89     "abc" <string-reader> 3 limit-stream unlimit-stream
90     "abc" <string-reader> =
91 ] unit-test
92
93 { t }
94 [
95     "abc" <string-reader> 3 limit-stream unlimit-stream
96     "abc" <string-reader> =
97 ] unit-test
98
99 { t }
100 [
101     [
102         "resource:license.txt" utf8 <file-reader> &dispose
103         3 limit-stream unlimit-stream
104         "resource:license.txt" utf8 <file-reader> &dispose
105         [ decoder? ] both?
106     ] with-destructors
107 ] unit-test
108
109 { "asdf" } [
110     "asdf" <string-reader> 2 <limited-stream> [
111         unlimited-input contents
112     ] with-input-stream
113 ] unit-test
114
115 { "asdf" } [
116     "asdf" <string-reader> 2 <limited-stream> [
117         [ contents ] with-unlimited-input
118     ] with-input-stream
119 ] unit-test
120
121 { "gh" } [
122     "asdfgh" <string-reader> 4 <limited-stream> [
123         2 [
124             [ contents drop ] with-unlimited-input
125         ] with-limited-input
126         [ contents ] with-unlimited-input
127     ] with-input-stream
128 ] unit-test
129
130 { 4 } [ B{ 0 1 2 3 4 5 } binary <byte-reader> 4 <limited-stream> stream-length ] unit-test
131 { 6 } [ B{ 0 1 2 3 4 5 } binary <byte-reader> 8 <limited-stream> stream-length ] unit-test