]> gitweb.factorcode.org Git - factor.git/blob - core/io/encodings/encodings-tests.factor
0ba65a88028b0c16e745aec12325b615c580f2a5
[factor.git] / core / io / encodings / encodings-tests.factor
1 USING: accessors io io.encodings io.encodings.ascii
2 io.encodings.utf8 io.files io.streams.byte-array
3 io.streams.string kernel namespaces tools.test ;
4 IN: io.encodings.tests
5
6 [ { } ]
7 [ "vocab:io/test/empty-file.txt" ascii file-lines ]
8 unit-test
9
10 : lines-test ( file encoding -- line1 line2 )
11     [ readln readln ] with-file-reader ;
12
13 [
14     "This is a line."
15     "This is another line."
16 ] [
17     "vocab:io/test/windows-eol.txt"
18     ascii lines-test
19 ] unit-test
20
21 [
22     "This is a line."
23     "This is another line."
24 ] [
25     "vocab:io/test/mac-os-eol.txt"
26     ascii lines-test
27 ] unit-test
28
29 [
30     "This is a line."
31     "This is another line."
32 ] [
33     "vocab:io/test/unix-eol.txt"
34     ascii 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
76
77 [ t ] [
78     "vocab:io/test/mac-os-eol.txt"
79     ascii [ 10 peek 10 peek = ] with-file-reader
80 ] unit-test
81
82 [ t ] [
83     "vocab:io/test/mac-os-eol.txt"
84     ascii [ peek1 peek1 = ] with-file-reader
85 ] unit-test