aboutsummaryrefslogtreecommitdiff
path: root/tests/datetime.rs
blob: 948e86310c8e56f339c0aa5d9b7a3d57104f4949 (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
55
56
57
58
extern crate toml;

use std::str::FromStr;

use toml::Value;

#[test]
fn times() {
    fn good(s: &str) {
        let to_parse = format!("foo = {}", s);
        let value = Value::from_str(&to_parse).unwrap();
        assert_eq!(value["foo"].as_datetime().unwrap().to_string(), s);
    }

    good("1997-09-09T09:09:09Z");
    good("1997-09-09T09:09:09+09:09");
    good("1997-09-09T09:09:09-09:09");
    good("1997-09-09T09:09:09");
    good("1997-09-09");
    good("09:09:09");
    good("1997-09-09T09:09:09.09Z");
    good("1997-09-09T09:09:09.09+09:09");
    good("1997-09-09T09:09:09.09-09:09");
    good("1997-09-09T09:09:09.09");
    good("09:09:09.09");
}

#[test]
fn bad_times() {
    fn bad(s: &str) {
        let to_parse = format!("foo = {}", s);
        assert!(Value::from_str(&to_parse).is_err());
    }

    bad("199-09-09");
    bad("199709-09");
    bad("1997-9-09");
    bad("1997-09-9");
    bad("1997-09-0909:09:09");
    bad("1997-09-09T09:09:09.");
    bad("T");
    bad("T.");
    bad("TZ");
    bad("1997-09-09T09:09:09.09+");
    bad("1997-09-09T09:09:09.09+09");
    bad("1997-09-09T09:09:09.09+09:9");
    bad("1997-09-09T09:09:09.09+0909");
    bad("1997-09-09T09:09:09.09-");
    bad("1997-09-09T09:09:09.09-09");
    bad("1997-09-09T09:09:09.09-09:9");
    bad("1997-09-09T09:09:09.09-0909");

    bad("1997-00-09T09:09:09.09Z");
    bad("1997-09-00T09:09:09.09Z");
    bad("1997-09-09T30:09:09.09Z");
    bad("1997-09-09T12:69:09.09Z");
    bad("1997-09-09T12:09:69.09Z");
}