1 #![cfg(all(
2     feature = "toml",
3     feature = "json",
4     feature = "hjson",
5     feature = "yaml",
6     feature = "ini",
7     feature = "ron",
8 ))]
9 
10 use self::chrono::{DateTime, TimeZone, Utc};
11 use self::config::*;
12 
make() -> Config13 fn make() -> Config {
14     Config::default()
15         .merge(File::from_str(
16             r#"
17             {
18                 "json_datetime": "2017-05-10T02:14:53Z"
19             }
20             "#,
21             FileFormat::Json,
22         ))
23         .unwrap()
24         .merge(File::from_str(
25             r#"
26             yaml_datetime: 2017-06-12T10:58:30Z
27             "#,
28             FileFormat::Yaml,
29         ))
30         .unwrap()
31         .merge(File::from_str(
32             r#"
33             toml_datetime = 2017-05-11T14:55:15Z
34             "#,
35             FileFormat::Toml,
36         ))
37         .unwrap()
38         .merge(File::from_str(
39             r#"
40             {
41                 "hjson_datetime": "2017-05-10T02:14:53Z"
42             }
43             "#,
44             FileFormat::Hjson,
45         ))
46         .unwrap()
47         .merge(File::from_str(
48             r#"
49                 ini_datetime = 2017-05-10T02:14:53Z
50             "#,
51             FileFormat::Ini,
52         ))
53         .unwrap()
54         .merge(File::from_str(
55             r#"
56             (
57                 ron_datetime: "2021-04-19T11:33:02Z"
58             )
59             "#,
60             FileFormat::Ron,
61         ))
62         .unwrap()
63         .clone()
64 }
65 
66 #[test]
test_datetime_string()67 fn test_datetime_string() {
68     let s = make();
69 
70     // JSON
71     let date: String = s.get("json_datetime").unwrap();
72 
73     assert_eq!(&date, "2017-05-10T02:14:53Z");
74 
75     // TOML
76     let date: String = s.get("toml_datetime").unwrap();
77 
78     assert_eq!(&date, "2017-05-11T14:55:15Z");
79 
80     // YAML
81     let date: String = s.get("yaml_datetime").unwrap();
82 
83     assert_eq!(&date, "2017-06-12T10:58:30Z");
84 
85     // HJSON
86     let date: String = s.get("hjson_datetime").unwrap();
87 
88     assert_eq!(&date, "2017-05-10T02:14:53Z");
89 
90     // INI
91     let date: String = s.get("ini_datetime").unwrap();
92 
93     assert_eq!(&date, "2017-05-10T02:14:53Z");
94 
95     // RON
96     let date: String = s.get("ron_datetime").unwrap();
97 
98     assert_eq!(&date, "2021-04-19T11:33:02Z");
99 }
100 
101 #[test]
test_datetime()102 fn test_datetime() {
103     let s = make();
104 
105     // JSON
106     let date: DateTime<Utc> = s.get("json_datetime").unwrap();
107 
108     assert_eq!(date, Utc.ymd(2017, 5, 10).and_hms(2, 14, 53));
109 
110     // TOML
111     let date: DateTime<Utc> = s.get("toml_datetime").unwrap();
112 
113     assert_eq!(date, Utc.ymd(2017, 5, 11).and_hms(14, 55, 15));
114 
115     // YAML
116     let date: DateTime<Utc> = s.get("yaml_datetime").unwrap();
117 
118     assert_eq!(date, Utc.ymd(2017, 6, 12).and_hms(10, 58, 30));
119 
120     // HJSON
121     let date: DateTime<Utc> = s.get("hjson_datetime").unwrap();
122 
123     assert_eq!(date, Utc.ymd(2017, 5, 10).and_hms(2, 14, 53));
124 
125     // INI
126     let date: DateTime<Utc> = s.get("ini_datetime").unwrap();
127 
128     assert_eq!(date, Utc.ymd(2017, 5, 10).and_hms(2, 14, 53));
129 
130     // RON
131     let date: DateTime<Utc> = s.get("ron_datetime").unwrap();
132 
133     assert_eq!(date, Utc.ymd(2021, 4, 19).and_hms(11, 33, 2));
134 }
135