]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/string/string-tests.factor
Merge OneEyed's patch
[factor.git] / basis / io / streams / string / string-tests.factor
1 USING: io.streams.string io kernel arrays namespaces make
2 tools.test ;
3 IN: io.streams.string.tests
4
5 [ "line 1" CHAR: l ]
6 [
7     "line 1\nline 2\nline 3" <string-reader>
8     dup stream-readln swap stream-read1
9 ]
10 unit-test
11
12 [ f ]
13 [ "" <string-reader> stream-readln ]
14 unit-test
15
16 [ "xyzzy" ] [ [ "xyzzy" write ] with-string-writer ] unit-test
17
18 [ "a" ] [ 1 "abc" <string-reader> stream-read ] unit-test
19 [ "ab" ] [ 2 "abc" <string-reader> stream-read ] unit-test
20 [ "abc" ] [ 3 "abc" <string-reader> stream-read ] unit-test
21 [ "abc" ] [ 4 "abc" <string-reader> stream-read ] unit-test
22 [ "abc" f ] [
23     3 "abc" <string-reader> [ stream-read ] keep stream-read1
24 ] unit-test
25
26 [
27     {
28         { "It seems " CHAR: J }
29         { "obs has lost h" CHAR: i }
30         { "s grasp on reality again.\n" f }
31     }
32 ] [
33     [
34         "It seems Jobs has lost his grasp on reality again.\n"
35         <string-reader> [
36             "J" read-until 2array ,
37             "i" read-until 2array ,
38             "X" read-until 2array ,
39         ] with-input-stream
40     ] { } make
41 ] unit-test
42
43 [ "hello" "hi" ] [
44     "hello\nhi" <string-reader>
45     dup stream-readln
46     2 rot stream-read
47 ] unit-test
48
49 [ "hello" "hi" ] [
50     "hello\r\nhi" <string-reader>
51     dup stream-readln
52     2 rot stream-read
53 ] unit-test
54
55 [ "hello" "hi" ] [
56     "hello\rhi" <string-reader>
57     dup stream-readln
58     2 rot stream-read
59 ] unit-test