]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/limited/limited-tests.factor
Create basis vocab root
[factor.git] / basis / io / streams / limited / limited-tests.factor
1 IN: io.streams.limited.tests
2 USING: io io.streams.limited io.encodings io.encodings.string
3 io.encodings.ascii io.encodings.binary io.streams.byte-array
4 namespaces tools.test strings kernel ;
5
6 [ ] [
7     "hello world\nhow are you today\nthis is a very long line indeed"
8     ascii encode binary <byte-reader> "data" set
9 ] unit-test
10
11 [ ] [ "data" get 24 <limited-stream> "limited" set ] unit-test
12
13 [ CHAR: h ] [ "limited" get stream-read1 ] unit-test
14
15 [ ] [ "limited" get ascii <decoder> "decoded" set ] unit-test
16
17 [ "ello world" ] [ "decoded" get stream-readln ] unit-test
18
19 [ "how " ] [ 4 "decoded" get stream-read ] unit-test
20
21 [ "decoded" get stream-readln ] [ limit-exceeded? ] must-fail-with
22
23 [ ] [
24     "abc\ndef\nghi"
25     ascii encode binary <byte-reader> "data" set
26 ] unit-test
27
28 [ ] [ "data" get 7 <limited-stream> "limited" set ] unit-test
29
30 [ "abc" CHAR: \n ] [ "\n" "limited" get stream-read-until [ >string ] dip ] unit-test
31
32 [ "\n" "limited" get stream-read-until ] [ limit-exceeded? ] must-fail-with
33
34 [ "he" CHAR: l ] [
35     B{ CHAR: h CHAR: e CHAR: l CHAR: l CHAR: o }
36     ascii <byte-reader> [
37         5 limit-input
38         "l" read-until
39     ] with-input-stream
40 ] unit-test