Merge branch 'emacs' of http://git.hacks-galore.org/jao/factor
[factor/jcg.git] / core / io / files / files-tests.factor
blobd2611d73a91482602793ee1b243bfaafd38691b6
1 USING: tools.test io.files io.files.private io.files.temp
2 io.directories io.encodings.8-bit arrays make system
3 io.encodings.binary io
4 threads kernel continuations io.encodings.ascii sequences
5 strings accessors io.encodings.utf8 math destructors namespaces
7 IN: io.files.tests
9 \ exists? must-infer
10 \ (exists?) must-infer
12 [ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test
14 [ ] [ "append-test" temp-file ascii <file-appender> dispose ] unit-test
17     "This is a line.\rThis is another line.\r"
18 ] [
19     "resource:core/io/test/mac-os-eol.txt" latin1 <file-reader>
20     [ 500 read ] with-input-stream
21 ] unit-test
24     255
25 ] [
26     "resource:core/io/test/binary.txt" latin1 <file-reader>
27     [ read1 ] with-input-stream >fixnum
28 ] unit-test
30 [ ] [
31     "It seems Jobs has lost his grasp on reality again.\n"
32     "separator-test.txt" temp-file latin1 set-file-contents
33 ] unit-test
36     {
37         { "It seems " CHAR: J }
38         { "obs has lost h" CHAR: i }
39         { "s grasp on reality again.\n" f }
40     }
41 ] [
42     [
43         "separator-test.txt" temp-file
44         latin1 <file-reader> [
45             "J" read-until 2array ,
46             "i" read-until 2array ,
47             "X" read-until 2array ,
48         ] with-input-stream
49     ] { } make
50 ] unit-test
52 [ ] [
53     image binary [
54         10 [ 65536 read drop ] times
55     ] with-file-reader
56 ] unit-test
58 ! Test EOF behavior
59 [ 10 ] [
60     image binary [
61         0 read drop
62         10 read length
63     ] with-file-reader
64 ] unit-test
66 USE: debugger.threads
68 [ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
70 [ ] [ "test-quux.txt" temp-file delete-file ] unit-test
72 [ ] [ "test-quux.txt" temp-file ascii [ [ yield "Hi" write ] "Test" spawn drop ] with-file-writer ] unit-test
74 [ ] [ "test-quux.txt" "quux-test.txt" [ temp-file ] bi@ move-file ] unit-test
76 [ t ] [ "quux-test.txt" temp-file exists? ] unit-test
78 [ ] [ "quux-test.txt" temp-file delete-file ] unit-test