Debian Codegraph @

tests/integration/chrono.rs

raw symbols SCIP
1 use crate::prelude::*;
2 use chrono04::{prelude::*, TimeDelta};
3
4 #[derive(JsonSchema, Serialize, Deserialize)]
5 struct ChronoTypes {
6 weekday: Weekday,
7 date_time: DateTime<Utc>,
8 naive_date: NaiveDate,
9 naive_date_time: NaiveDateTime,
10 naive_time: NaiveTime,
11 time_delta: TimeDelta,
12 }
13
14 #[test]
15 fn chrono() {
16 test!(ChronoTypes).assert_snapshot();
17
18 test!(Weekday)
19 .assert_allows_ser_roundtrip([Weekday::Mon])
20 .assert_matches_de_roundtrip(arbitrary_values());
21
22 test!(DateTime<Utc>)
23 .assert_allows_ser_roundtrip_default()
24 // JSON Schema only allows dates with 4-digit years
25 // .assert_allows_ser_roundtrip([DateTime::<Utc>::MIN_UTC, DateTime::<Utc>::MAX_UTC])
26 .assert_matches_de_roundtrip(arbitrary_values());
27
28 test!(NaiveDate)
29 .assert_allows_ser_roundtrip_default()
30 // JSON Schema only allows dates with 4-digit years
31 // .assert_allows_ser_roundtrip([NaiveDate::MIN, NaiveDate::MAX])
32 .assert_matches_de_roundtrip(arbitrary_values());
33
34 test!(NaiveDateTime)
35 .assert_allows_ser_roundtrip_default()
36 // JSON Schema only allows dates with 4-digit years
37 // .assert_allows_ser_roundtrip([NaiveDateTime::MIN, NaiveDateTime::MAX])
38 .assert_matches_de_roundtrip(arbitrary_values_except(
39 Value::is_string,
40 "Custom format 'partial-date-time', so arbitrary strings technically allowed by schema",
41 ));
42
43 test!(NaiveTime)
44 .assert_allows_ser_roundtrip_default()
45 .assert_allows_ser_roundtrip([NaiveTime::MIN, NaiveDateTime::MAX.time()])
46 .assert_matches_de_roundtrip(arbitrary_values_except(
47 Value::is_string,
48 "Custom format 'date-time', so arbitrary strings technically allowed by schema",
49 ));
50
51 test!(TimeDelta)
52 .assert_allows_ser_roundtrip_default()
53 .assert_allows_ser_roundtrip([TimeDelta::MIN, TimeDelta::MAX])
54 .assert_rejects_de([json!([0, -1]), json!([0, 1_000_000_000])])
55 .assert_matches_de_roundtrip(arbitrary_values());
56 }