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