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