blob: f3b77e35cc7689160f57162f6df368698b604ed4 (
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
59
60
61
62
|
extern crate toml;
use std::str::FromStr;
use toml::Value;
#[test]
fn times() {
fn dogood(s: &str, serialized: &str) {
let to_parse = format!("foo = {}", s);
let value = Value::from_str(&to_parse).unwrap();
assert_eq!(value["foo"].as_datetime().unwrap().to_string(), serialized);
}
fn good(s: &str) {
dogood(s, s);
dogood(&s.replace("T", " "), 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");
}
|