2 USING: io kernel math parser strings test ;
5 "resource:/core/test/io/no-trailing-eol.factor" run-file
8 : <resource-reader> ( resource -- stream )
9 resource-path <file-reader> ;
11 : lines-test ( stream -- line1 line2 )
12 [ readln readln ] with-stream ;
16 "This is another line."
18 "/core/test/io/windows-eol.txt" <resource-reader> lines-test
23 "This is another line."
25 "/core/test/io/mac-os-eol.txt" <resource-reader> lines-test
30 "This is another line."
32 "/core/test/io/unix-eol.txt" <resource-reader> lines-test
36 "This is a line.\rThis is another line.\r"
38 "/core/test/io/mac-os-eol.txt" <resource-reader>
39 [ 500 read ] with-stream
45 "/core/test/io/binary.txt" <resource-reader>
46 [ read1 ] with-stream >fixnum
49 ! Make sure we use correct to_c_string form when writing
50 [ ] [ "\0" write ] unit-test
52 [ "" ] [ 0 read ] unit-test
54 ! [ ] [ "123" write 9000 CHAR: x <string> write flush ] unit-test
58 "line 1\nline 2\nline 3" <string-reader>
59 dup stream-readln swap stream-read1
64 [ "" <string-reader> stream-readln ]
67 [ ] [ 10000 f set-timeout ] unit-test
70 "/core/test/io/binary.txt" <resource-reader>
71 [ 0.2 read ] with-stream
75 [ "/core/test/io/empty-file.txt" <resource-reader> lines ]
78 [ "xyzzy" ] [ [ "xyzzy" write ] string-out ] unit-test
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