]> gitweb.factorcode.org Git - factor.git/blob - core/io/encodings/encodings-tests.factor
Fix permission bits
[factor.git] / core / io / encodings / encodings-tests.factor
1 USING: io.files io.streams.string io io.streams.byte-array
2 tools.test kernel io.encodings.ascii io.encodings.utf8
3 namespaces accessors io.encodings ;
4 IN: io.streams.encodings.tests
5
6 [ { } ]
7 [ "resource:core/io/test/empty-file.txt" ascii <file-reader> lines ]
8 unit-test
9
10 : lines-test ( stream -- line1 line2 )
11     [ readln readln ] with-input-stream ;
12
13 [
14     "This is a line."
15     "This is another line."
16 ] [
17     "resource:core/io/test/windows-eol.txt"
18     ascii <file-reader> lines-test
19 ] unit-test
20
21 [
22     "This is a line."
23     "This is another line."
24 ] [
25     "resource:core/io/test/mac-os-eol.txt"
26     ascii <file-reader> lines-test
27 ] unit-test
28
29 [
30     "This is a line."
31     "This is another line."
32 ] [
33     "resource:core/io/test/unix-eol.txt"
34     ascii <file-reader> lines-test
35 ] unit-test
36
37 [
38     "1234"
39 ] [
40      "Hello world\r\n1234" <string-reader>
41      dup stream-readln drop
42      4 swap stream-read
43 ] unit-test
44
45 [
46     "1234"
47 ] [
48      "Hello world\r\n1234" <string-reader>
49      dup stream-readln drop
50      4 swap stream-read-partial
51 ] unit-test
52
53 [
54     CHAR: 1
55 ] [
56      "Hello world\r\n1234" <string-reader>
57      dup stream-readln drop
58      stream-read1
59 ] unit-test
60
61 [ utf8 ascii ] [
62     "foo" utf8 [
63         input-stream get code>>
64         ascii decode-input
65         input-stream get code>>
66     ] with-byte-reader
67 ] unit-test
68
69 [ utf8 ascii ] [
70     utf8 [
71         output-stream get code>>
72         ascii encode-output
73         output-stream get code>>
74     ] with-byte-writer drop
75 ] unit-test