]> gitweb.factorcode.org Git - factor.git/blob - core/io/io-tests.factor
c38a7c9ebc70286ed7b46a9e55488e08b6d41572
[factor.git] / core / io / io-tests.factor
1 USING: arrays io io.files kernel math parser strings system
2 tools.test words namespaces make io.encodings.8-bit
3 io.encodings.binary sequences ;
4 IN: io.tests
5
6 [ f ] [
7     "resource:core/io/test/no-trailing-eol.factor" run-file
8     "foo" "io.tests" lookup
9 ] unit-test
10
11 [
12     "This is a line.\rThis is another line.\r"
13 ] [
14     "resource:core/io/test/mac-os-eol.txt" latin1 <file-reader>
15     [ 500 read ] with-input-stream
16 ] unit-test
17
18 [
19     255
20 ] [
21     "resource:core/io/test/binary.txt" latin1 <file-reader>
22     [ read1 ] with-input-stream >fixnum
23 ] unit-test
24
25 ! Make sure we use correct to_c_string form when writing
26 [ ] [ "\0" write ] unit-test
27
28 [
29     {
30         { "It seems " CHAR: J }
31         { "obs has lost h" CHAR: i }
32         { "s grasp on reality again.\n" f }
33     }
34 ] [
35     [
36         "resource:core/io/test/separator-test.txt"
37         latin1 <file-reader> [
38             "J" read-until 2array ,
39             "i" read-until 2array ,
40             "X" read-until 2array ,
41         ] with-input-stream
42     ] { } make
43 ] unit-test
44
45 [ ] [
46     image binary [
47         10 [ 65536 read drop ] times
48     ] with-file-reader
49 ] unit-test
50
51 ! Test EOF behavior
52 [ 10 ] [
53     image binary [
54         0 read drop
55         10 read length
56     ] with-file-reader
57 ] unit-test