1 USING: arrays debugger.threads destructors io io.directories
2 io.encodings.ascii io.encodings.binary io.encodings.string
3 io.encodings.8-bit.latin1 io.files io.files.private
4 io.files.temp io.files.unique kernel make math sequences system
5 threads tools.test generic.single specialized-arrays alien.c-types ;
9 [ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test
11 [ ] [ "append-test" temp-file ascii <file-appender> dispose ] unit-test
14 "This is a line.\rThis is another line.\r"
16 "vocab:io/test/mac-os-eol.txt" latin1
17 [ 500 read ] with-file-reader
23 "vocab:io/test/binary.txt" latin1
24 [ read1 ] with-file-reader >fixnum
30 "vocab:io/test/read-until-test.txt" ascii
31 [ " " read-until ] with-file-reader
37 "vocab:io/test/read-until-test.txt" binary
38 [ " " read-until [ ascii decode ] dip ] with-file-reader
42 "It seems Jobs has lost his grasp on reality again.\n"
43 "separator-test.txt" temp-file latin1 set-file-contents
48 { "It seems " CHAR: J }
49 { "obs has lost h" CHAR: i }
50 { "s grasp on reality again.\n" f }
54 "separator-test.txt" temp-file
56 "J" read-until 2array ,
57 "i" read-until 2array ,
58 "X" read-until 2array ,
65 10 [ 65536 read drop ] times
69 ! Writing specialized arrays to binary streams should work
71 "test.txt" temp-file binary [
72 int-array{ 1 2 3 } write
76 [ int-array{ 1 2 3 } ] [
77 "test.txt" temp-file binary [
83 ! Writing strings to binary streams should fail
85 "test.txt" temp-file binary [
98 ! Make sure that writing to a closed stream from another thread doesn't crash
99 [ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
101 [ ] [ "test-quux.txt" temp-file delete-file ] unit-test
103 [ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
105 [ ] [ "test-quux.txt" "quux-test.txt" [ temp-file ] bi@ move-file ] unit-test
107 [ t ] [ "quux-test.txt" temp-file exists? ] unit-test
109 [ ] [ "quux-test.txt" temp-file delete-file ] unit-test
114 "seek-test1" unique-file binary
117 B{ 1 2 3 4 5 } write 0 seek-absolute seek-output
127 "seek-test2" unique-file binary
130 B{ 1 2 3 4 5 } write -1 seek-relative seek-output
138 [ B{ 1 2 3 4 5 0 3 } ]
140 "seek-test3" unique-file binary
143 B{ 1 2 3 4 5 } write 1 seek-relative seek-output
153 B{ 1 2 3 4 5 } "seek-test4" unique-file binary [
157 -3 seek-end seek-input 1 read
164 B{ 1 2 3 4 5 } "seek-test5" unique-file binary [
168 3 seek-absolute seek-input
169 -2 seek-relative seek-input
176 "seek-test6" unique-file binary [
177 -10 seek-absolute seek-input
182 "non-string-error" unique-file ascii [
185 ] [ no-method? ] must-fail-with
188 "non-byte-array-error" unique-file binary [
191 ] [ no-method? ] must-fail-with
193 ! What happens if we close a file twice?
195 "closing-twice" unique-file ascii <file-writer>
196 [ dispose ] [ dispose ] bi