1 USING: arrays debugger.threads destructors io io.directories
2 io.encodings.ascii io.encodings.binary
3 io.files io.files.private io.files.temp io.files.unique kernel
4 make math sequences system threads tools.test generic.single
5 io.encodings.8-bit.latin1 ;
8 [ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test
10 [ ] [ "append-test" temp-file ascii <file-appender> dispose ] unit-test
13 "This is a line.\rThis is another line.\r"
15 "vocab:io/test/mac-os-eol.txt" latin1
16 [ 500 read ] with-file-reader
22 "vocab:io/test/binary.txt" latin1
23 [ read1 ] with-file-reader >fixnum
27 "It seems Jobs has lost his grasp on reality again.\n"
28 "separator-test.txt" temp-file latin1 set-file-contents
33 { "It seems " CHAR: J }
34 { "obs has lost h" CHAR: i }
35 { "s grasp on reality again.\n" f }
39 "separator-test.txt" temp-file
41 "J" read-until 2array ,
42 "i" read-until 2array ,
43 "X" read-until 2array ,
50 10 [ 65536 read drop ] times
64 [ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
66 [ ] [ "test-quux.txt" temp-file delete-file ] unit-test
68 [ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
70 [ ] [ "test-quux.txt" "quux-test.txt" [ temp-file ] bi@ move-file ] unit-test
72 [ t ] [ "quux-test.txt" temp-file exists? ] unit-test
74 [ ] [ "quux-test.txt" temp-file delete-file ] unit-test
79 "seek-test1" unique-file binary
82 B{ 1 2 3 4 5 } write 0 seek-absolute seek-output
92 "seek-test2" unique-file binary
95 B{ 1 2 3 4 5 } write -1 seek-relative seek-output
103 [ B{ 1 2 3 4 5 0 3 } ]
105 "seek-test3" unique-file binary
108 B{ 1 2 3 4 5 } write 1 seek-relative seek-output
118 B{ 1 2 3 4 5 } "seek-test4" unique-file binary [
122 -3 seek-end seek-input 1 read
129 B{ 1 2 3 4 5 } "seek-test5" unique-file binary [
133 3 seek-absolute seek-input
134 -2 seek-relative seek-input
141 "seek-test6" unique-file binary [
142 -10 seek-absolute seek-input
147 "non-string-error" unique-file ascii [
150 ] [ no-method? ] must-fail-with
153 "non-byte-array-error" unique-file binary [
156 ] [ no-method? ] must-fail-with
158 ! What happens if we close a file twice?
160 "closing-twice" unique-file ascii <file-writer>
161 [ dispose ] [ dispose ] bi