]> gitweb.factorcode.org Git - factor.git/blob - core/test/io/io.factor
more sql changes
[factor.git] / core / test / io / io.factor
1 IN: temporary
2 USING: io kernel math parser strings test ;
3
4 [ 4 ] [
5     "resource:/core/test/io/no-trailing-eol.factor" run-file
6 ] unit-test
7
8 : <resource-reader> ( resource -- stream )
9     resource-path <file-reader> ;
10
11 : lines-test ( stream -- line1 line2 )
12     [ readln readln ] with-stream ;
13
14 [
15     "This is a line."
16     "This is another line."
17 ] [
18     "/core/test/io/windows-eol.txt" <resource-reader> lines-test
19 ] unit-test
20
21 [
22     "This is a line."
23     "This is another line."
24 ] [
25     "/core/test/io/mac-os-eol.txt" <resource-reader> lines-test
26 ] unit-test
27
28 [
29     "This is a line."
30     "This is another line."
31 ] [
32     "/core/test/io/unix-eol.txt" <resource-reader> lines-test
33 ] unit-test
34
35 [
36     "This is a line.\rThis is another line.\r"
37 ] [
38     "/core/test/io/mac-os-eol.txt" <resource-reader>
39     [ 500 read ] with-stream
40 ] unit-test
41
42 [
43     255
44 ] [
45     "/core/test/io/binary.txt" <resource-reader>
46     [ read1 ] with-stream >fixnum
47 ] unit-test
48
49 ! Make sure we use correct to_c_string form when writing
50 [ ] [ "\0" write ] unit-test
51
52 [ "" ] [ 0 read ] unit-test
53
54 ! [ ] [ "123" write 9000 CHAR: x <string> write flush ] unit-test
55
56 [ "line 1" CHAR: l ]
57 [
58     "line 1\nline 2\nline 3" <string-reader>
59     dup stream-readln swap stream-read1
60 ]
61 unit-test
62
63 [ f ]
64 [ "" <string-reader> stream-readln ]
65 unit-test
66
67 [ ] [ 10000 f set-timeout ] unit-test
68
69 [ "" ] [
70     "/core/test/io/binary.txt" <resource-reader>
71     [ 0.2 read ] with-stream
72 ] unit-test
73
74 [ { } ]
75 [ "/core/test/io/empty-file.txt" <resource-reader> lines ]
76 unit-test
77
78 [ "xyzzy" ] [ [ "xyzzy" write ] string-out ] unit-test
79
80 [ { "" } ] [ "" string-lines ] unit-test
81 [ { "" "" } ] [ "\n" string-lines ] unit-test
82 [ { "" "" } ] [ "\r" string-lines ] unit-test
83 [ { "" "" } ] [ "\r\n" string-lines ] unit-test
84 [ { "hello" } ] [ "hello" string-lines ] unit-test
85 [ { "hello" "" } ] [ "hello\n" string-lines ] unit-test
86 [ { "hello" "" } ] [ "hello\r" string-lines ] unit-test
87 [ { "hello" "" } ] [ "hello\r\n" string-lines ] unit-test
88 [ { "hello" "hi" } ] [ "hello\nhi" string-lines ] unit-test
89 [ { "hello" "hi" } ] [ "hello\rhi" string-lines ] unit-test
90 [ { "hello" "hi" } ] [ "hello\r\nhi" string-lines ] unit-test