Skip to content

Commit

Permalink
Add new test cases
Browse files Browse the repository at this point in the history
Many of the tests fail currently
  • Loading branch information
jonasbb committed Jul 21, 2024
1 parent 2472f0a commit 419f051
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion serde_with/tests/chrono_0_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ extern crate alloc;
mod utils;

use crate::utils::{
check_deserialization, check_error_deserialization, check_serialization, is_equal,
check_deserialization, check_error_deserialization, check_error_serialization,
check_serialization, is_equal,
};
use alloc::collections::BTreeMap;
use chrono_0_4::{DateTime, Duration, Local, NaiveDateTime, Utc};
Expand Down Expand Up @@ -741,3 +742,55 @@ fn test_naive_datetime_smoketest() {
NaiveDateTime, "TimestampSecondsWithFrac", zero - Duration::seconds(1), {expect![[r#"-1.0"#]]};
};
}

#[test]
fn bug771_extreme_nanoseconds() {
#[serde_as]
#[derive(Debug, Serialize)]
struct S(#[serde_as(as = "serde_with::TimestampNanoSeconds")] DateTime<Utc>);

check_error_serialization(
S(DateTime::<Utc>::MIN_UTC),
expect!["Failed to serialize value as the value cannot be represented."],
);
check_error_serialization(
S("1385-06-12T00:25:26.290448384Z".parse().unwrap()),
expect!["Failed to serialize value as the value cannot be represented."],
);
check_error_serialization(
S("1385-06-12T00:25:26.290448385Z".parse().unwrap()),
expect!["Failed to serialize value as the value cannot be represented."],
);
check_error_serialization(
S("1677-09-21T00:12:43.145224191Z".parse().unwrap()),
expect!["Failed to serialize value as the value cannot be represented."],
);
check_error_serialization(
S("1677-09-21T00:12:43.145224192Z".parse().unwrap()),
expect!["Failed to serialize value as the value cannot be represented."],
);
check_serialization(
S("1677-09-21T00:12:43.145224193Z".parse().unwrap()),
expect!["-9223372036854775807"],
);
check_serialization(
S("2262-04-11T23:47:16.854775807Z".parse().unwrap()),
expect!["9223372036854775807"],
);
check_error_serialization(
S("2262-04-11T23:47:16.854775808Z".parse().unwrap()),
expect!["Failed to serialize value as the value cannot be represented."],
);
check_error_serialization(
S("2554-07-21T23:34:33.709551615Z".parse().unwrap()),
expect!["Failed to serialize value as the value cannot be represented."],
);
check_error_serialization(
S("2554-07-21T23:34:33.709551616Z".parse().unwrap()),
expect!["Failed to serialize value as the value cannot be represented."],
);
check_error_serialization(
S(DateTime::<Utc>::MAX_UTC),
expect!["Failed to serialize value as the value cannot be represented."],
);
}

0 comments on commit 419f051

Please sign in to comment.