about summary refs log tree commit diff
path: root/src/test/stdtest/io.rs
blob: 1c9774b7fe60ce05db30052f09f59bd7849a1a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import core::*;

// -*- rust -*-
use std;
import std::io;
import str;
import result;

#[test]
fn test_simple() {
    let tmpfile: str = "tmp/lib-io-test-simple.tmp";
    log tmpfile;
    let frood: str = "A hoopy frood who really knows where his towel is.";
    log frood;
    {
        let out: io::writer =
            result::get(io::file_writer(tmpfile, [io::create, io::truncate]));
        out.write_str(frood);
    }
    let inp: io::reader = result::get(io::file_reader(tmpfile));
    let frood2: str = inp.read_c_str();
    log frood2;
    assert (str::eq(frood, frood2));
}

#[test]
fn file_reader_not_exist() {
    alt io::file_reader("not a file") {
      result::err(e) {
        assert e == "error opening not a file";
      }
      result::ok(_) { fail; }
    }
}

#[test]
fn file_buf_writer_bad_name() {
    alt io::file_buf_writer("?/?", []) {
      result::err(e) {
        assert e == "error opening ?/?";
      }
      result::ok(_) { fail; }
    }
}

#[test]
fn buffered_file_buf_writer_bad_name() {
    alt io::buffered_file_buf_writer("?/?") {
      result::err(e) {
        assert e == "error opening ?/?";
      }
      result::ok(_) { fail; }
    }
}