PageRenderTime 216ms CodeModel.GetById 212ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/core/io/streams/c/c-tests.factor

http://github.com/abeaumont/factor
Unknown | 33 lines | 28 code | 5 blank | 0 comment | 0 complexity | fe4588a6ad93a52c9ea4730a4061e9d6 MD5 | raw file
 1USING: tools.test io.files io.files.temp io io.streams.c
 2io.encodings.ascii strings destructors kernel specialized-arrays
 3alien.c-types math alien.data ;
 4SPECIALIZED-ARRAY: int
 5IN: io.streams.c.tests
 6
 7[ "hello world" ] [
 8    "hello world" "test.txt" temp-file ascii set-file-contents
 9
10    "test.txt" temp-file "rb" fopen <c-reader> stream-contents
11    >string
12] unit-test
13
14! Writing specialized arrays to binary streams
15[ ] [
16    "test.txt" temp-file "wb" fopen <c-writer> [
17        int-array{ 1 2 3 } write
18    ] with-output-stream
19] unit-test
20
21[ int-array{ 1 2 3 } ] [
22    "test.txt" temp-file "rb" fopen <c-reader> [
23        3 4 * read
24    ] with-input-stream
25    int cast-array
26] unit-test
27
28! Writing strings to binary streams should fail
29[
30    "test.txt" temp-file "wb" fopen <c-writer> [
31        "OMGFAIL" write
32    ] with-output-stream
33] must-fail