Get rid of deprecated chrono
functions in juniper
tests
This commit is contained in:
parent
f1ecde260c
commit
b172d51b6e
1 changed files with 56 additions and 48 deletions
|
@ -337,8 +337,8 @@ mod date_test {
|
||||||
#[test]
|
#[test]
|
||||||
fn parses_correct_input() {
|
fn parses_correct_input() {
|
||||||
for (raw, expected) in [
|
for (raw, expected) in [
|
||||||
("1996-12-19", Date::from_ymd(1996, 12, 19)),
|
("1996-12-19", Date::from_ymd_opt(1996, 12, 19)),
|
||||||
("1564-01-30", Date::from_ymd(1564, 01, 30)),
|
("1564-01-30", Date::from_ymd_opt(1564, 01, 30)),
|
||||||
] {
|
] {
|
||||||
let input: InputValue = graphql_input_value!((raw));
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
let parsed = Date::from_input_value(&input);
|
let parsed = Date::from_input_value(&input);
|
||||||
|
@ -348,7 +348,7 @@ mod date_test {
|
||||||
"failed to parse `{raw}`: {:?}",
|
"failed to parse `{raw}`: {:?}",
|
||||||
parsed.unwrap_err(),
|
parsed.unwrap_err(),
|
||||||
);
|
);
|
||||||
assert_eq!(parsed.unwrap(), expected, "input: {raw}");
|
assert_eq!(parsed.unwrap(), expected.unwrap(), "input: {raw}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,18 +379,19 @@ mod date_test {
|
||||||
fn formats_correctly() {
|
fn formats_correctly() {
|
||||||
for (val, expected) in [
|
for (val, expected) in [
|
||||||
(
|
(
|
||||||
Date::from_ymd(1996, 12, 19),
|
Date::from_ymd_opt(1996, 12, 19),
|
||||||
graphql_input_value!("1996-12-19"),
|
graphql_input_value!("1996-12-19"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Date::from_ymd(1564, 01, 30),
|
Date::from_ymd_opt(1564, 01, 30),
|
||||||
graphql_input_value!("1564-01-30"),
|
graphql_input_value!("1564-01-30"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Date::from_ymd(2020, 01, 01),
|
Date::from_ymd_opt(2020, 01, 01),
|
||||||
graphql_input_value!("2020-01-01"),
|
graphql_input_value!("2020-01-01"),
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
|
let val = val.unwrap();
|
||||||
let actual: InputValue = val.to_input_value();
|
let actual: InputValue = val.to_input_value();
|
||||||
|
|
||||||
assert_eq!(actual, expected, "on value: {val}");
|
assert_eq!(actual, expected, "on value: {val}");
|
||||||
|
@ -407,12 +408,15 @@ mod local_time_test {
|
||||||
#[test]
|
#[test]
|
||||||
fn parses_correct_input() {
|
fn parses_correct_input() {
|
||||||
for (raw, expected) in [
|
for (raw, expected) in [
|
||||||
("14:23:43", LocalTime::from_hms(14, 23, 43)),
|
("14:23:43", LocalTime::from_hms_opt(14, 23, 43)),
|
||||||
("14:00:00", LocalTime::from_hms(14, 00, 00)),
|
("14:00:00", LocalTime::from_hms_opt(14, 00, 00)),
|
||||||
("14:00", LocalTime::from_hms(14, 00, 00)),
|
("14:00", LocalTime::from_hms_opt(14, 00, 00)),
|
||||||
("14:32", LocalTime::from_hms(14, 32, 00)),
|
("14:32", LocalTime::from_hms_opt(14, 32, 00)),
|
||||||
("14:00:00.000", LocalTime::from_hms(14, 00, 00)),
|
("14:00:00.000", LocalTime::from_hms_opt(14, 00, 00)),
|
||||||
("14:23:43.345", LocalTime::from_hms_milli(14, 23, 43, 345)),
|
(
|
||||||
|
"14:23:43.345",
|
||||||
|
LocalTime::from_hms_milli_opt(14, 23, 43, 345),
|
||||||
|
),
|
||||||
] {
|
] {
|
||||||
let input: InputValue = graphql_input_value!((raw));
|
let input: InputValue = graphql_input_value!((raw));
|
||||||
let parsed = LocalTime::from_input_value(&input);
|
let parsed = LocalTime::from_input_value(&input);
|
||||||
|
@ -422,7 +426,7 @@ mod local_time_test {
|
||||||
"failed to parse `{raw}`: {:?}",
|
"failed to parse `{raw}`: {:?}",
|
||||||
parsed.unwrap_err(),
|
parsed.unwrap_err(),
|
||||||
);
|
);
|
||||||
assert_eq!(parsed.unwrap(), expected, "input: {raw}");
|
assert_eq!(parsed.unwrap(), expected.unwrap(), "input: {raw}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,22 +461,23 @@ mod local_time_test {
|
||||||
fn formats_correctly() {
|
fn formats_correctly() {
|
||||||
for (val, expected) in [
|
for (val, expected) in [
|
||||||
(
|
(
|
||||||
LocalTime::from_hms_micro(1, 2, 3, 4005),
|
LocalTime::from_hms_micro_opt(1, 2, 3, 4005),
|
||||||
graphql_input_value!("01:02:03.004"),
|
graphql_input_value!("01:02:03.004"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
LocalTime::from_hms(0, 0, 0),
|
LocalTime::from_hms_opt(0, 0, 0),
|
||||||
graphql_input_value!("00:00:00"),
|
graphql_input_value!("00:00:00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
LocalTime::from_hms(12, 0, 0),
|
LocalTime::from_hms_opt(12, 0, 0),
|
||||||
graphql_input_value!("12:00:00"),
|
graphql_input_value!("12:00:00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
LocalTime::from_hms(1, 2, 3),
|
LocalTime::from_hms_opt(1, 2, 3),
|
||||||
graphql_input_value!("01:02:03"),
|
graphql_input_value!("01:02:03"),
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
|
let val = val.unwrap();
|
||||||
let actual: InputValue = val.to_input_value();
|
let actual: InputValue = val.to_input_value();
|
||||||
|
|
||||||
assert_eq!(actual, expected, "on value: {val}");
|
assert_eq!(actual, expected, "on value: {val}");
|
||||||
|
@ -494,15 +499,15 @@ mod local_date_time_test {
|
||||||
(
|
(
|
||||||
"1996-12-19 14:23:43",
|
"1996-12-19 14:23:43",
|
||||||
LocalDateTime::new(
|
LocalDateTime::new(
|
||||||
NaiveDate::from_ymd(1996, 12, 19),
|
NaiveDate::from_ymd_opt(1996, 12, 19).unwrap(),
|
||||||
NaiveTime::from_hms(14, 23, 43),
|
NaiveTime::from_hms_opt(14, 23, 43).unwrap(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"1564-01-30 14:00:00",
|
"1564-01-30 14:00:00",
|
||||||
LocalDateTime::new(
|
LocalDateTime::new(
|
||||||
NaiveDate::from_ymd(1564, 1, 30),
|
NaiveDate::from_ymd_opt(1564, 1, 30).unwrap(),
|
||||||
NaiveTime::from_hms(14, 00, 00),
|
NaiveTime::from_hms_opt(14, 00, 00).unwrap(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
|
@ -552,15 +557,15 @@ mod local_date_time_test {
|
||||||
for (val, expected) in [
|
for (val, expected) in [
|
||||||
(
|
(
|
||||||
LocalDateTime::new(
|
LocalDateTime::new(
|
||||||
NaiveDate::from_ymd(1996, 12, 19),
|
NaiveDate::from_ymd_opt(1996, 12, 19).unwrap(),
|
||||||
NaiveTime::from_hms(0, 0, 0),
|
NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
|
||||||
),
|
),
|
||||||
graphql_input_value!("1996-12-19 00:00:00"),
|
graphql_input_value!("1996-12-19 00:00:00"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
LocalDateTime::new(
|
LocalDateTime::new(
|
||||||
NaiveDate::from_ymd(1564, 1, 30),
|
NaiveDate::from_ymd_opt(1564, 1, 30).unwrap(),
|
||||||
NaiveTime::from_hms(14, 0, 0),
|
NaiveTime::from_hms_opt(14, 0, 0).unwrap(),
|
||||||
),
|
),
|
||||||
graphql_input_value!("1564-01-30 14:00:00"),
|
graphql_input_value!("1564-01-30 14:00:00"),
|
||||||
),
|
),
|
||||||
|
@ -590,40 +595,40 @@ mod date_time_test {
|
||||||
"2014-11-28T21:00:09+09:00",
|
"2014-11-28T21:00:09+09:00",
|
||||||
DateTime::<FixedOffset>::from_utc(
|
DateTime::<FixedOffset>::from_utc(
|
||||||
NaiveDateTime::new(
|
NaiveDateTime::new(
|
||||||
NaiveDate::from_ymd(2014, 11, 28),
|
NaiveDate::from_ymd_opt(2014, 11, 28).unwrap(),
|
||||||
NaiveTime::from_hms(12, 0, 9),
|
NaiveTime::from_hms_opt(12, 0, 9).unwrap(),
|
||||||
),
|
),
|
||||||
FixedOffset::east(9 * 3600),
|
FixedOffset::east_opt(9 * 3600).unwrap(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"2014-11-28T21:00:09Z",
|
"2014-11-28T21:00:09Z",
|
||||||
DateTime::<FixedOffset>::from_utc(
|
DateTime::<FixedOffset>::from_utc(
|
||||||
NaiveDateTime::new(
|
NaiveDateTime::new(
|
||||||
NaiveDate::from_ymd(2014, 11, 28),
|
NaiveDate::from_ymd_opt(2014, 11, 28).unwrap(),
|
||||||
NaiveTime::from_hms(21, 0, 9),
|
NaiveTime::from_hms_opt(21, 0, 9).unwrap(),
|
||||||
),
|
),
|
||||||
FixedOffset::east(0),
|
FixedOffset::east_opt(0).unwrap(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"2014-11-28T21:00:09+00:00",
|
"2014-11-28T21:00:09+00:00",
|
||||||
DateTime::<FixedOffset>::from_utc(
|
DateTime::<FixedOffset>::from_utc(
|
||||||
NaiveDateTime::new(
|
NaiveDateTime::new(
|
||||||
NaiveDate::from_ymd(2014, 11, 28),
|
NaiveDate::from_ymd_opt(2014, 11, 28).unwrap(),
|
||||||
NaiveTime::from_hms(21, 0, 9),
|
NaiveTime::from_hms_opt(21, 0, 9).unwrap(),
|
||||||
),
|
),
|
||||||
FixedOffset::east(0),
|
FixedOffset::east_opt(0).unwrap(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"2014-11-28T21:00:09.05+09:00",
|
"2014-11-28T21:00:09.05+09:00",
|
||||||
DateTime::<FixedOffset>::from_utc(
|
DateTime::<FixedOffset>::from_utc(
|
||||||
NaiveDateTime::new(
|
NaiveDateTime::new(
|
||||||
NaiveDate::from_ymd(2014, 11, 28),
|
NaiveDate::from_ymd_opt(2014, 11, 28).unwrap(),
|
||||||
NaiveTime::from_hms_milli(12, 0, 9, 50),
|
NaiveTime::from_hms_milli_opt(12, 0, 9, 50).unwrap(),
|
||||||
),
|
),
|
||||||
FixedOffset::east(0),
|
FixedOffset::east_opt(0).unwrap(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
|
@ -679,20 +684,20 @@ mod date_time_test {
|
||||||
(
|
(
|
||||||
DateTime::<FixedOffset>::from_utc(
|
DateTime::<FixedOffset>::from_utc(
|
||||||
NaiveDateTime::new(
|
NaiveDateTime::new(
|
||||||
NaiveDate::from_ymd(1996, 12, 19),
|
NaiveDate::from_ymd_opt(1996, 12, 19).unwrap(),
|
||||||
NaiveTime::from_hms(0, 0, 0),
|
NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
|
||||||
),
|
),
|
||||||
FixedOffset::east(0),
|
FixedOffset::east_opt(0).unwrap(),
|
||||||
),
|
),
|
||||||
graphql_input_value!("1996-12-19T00:00:00Z"),
|
graphql_input_value!("1996-12-19T00:00:00Z"),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
DateTime::<FixedOffset>::from_utc(
|
DateTime::<FixedOffset>::from_utc(
|
||||||
NaiveDateTime::new(
|
NaiveDateTime::new(
|
||||||
NaiveDate::from_ymd(1564, 1, 30),
|
NaiveDate::from_ymd_opt(1564, 1, 30).unwrap(),
|
||||||
NaiveTime::from_hms_milli(5, 0, 0, 123),
|
NaiveTime::from_hms_milli_opt(5, 0, 0, 123).unwrap(),
|
||||||
),
|
),
|
||||||
FixedOffset::east(9 * 3600),
|
FixedOffset::east_opt(9 * 3600).unwrap(),
|
||||||
),
|
),
|
||||||
graphql_input_value!("1564-01-30T05:00:00.123Z"),
|
graphql_input_value!("1564-01-30T05:00:00.123Z"),
|
||||||
),
|
),
|
||||||
|
@ -760,22 +765,25 @@ mod integration_test {
|
||||||
#[graphql_object]
|
#[graphql_object]
|
||||||
impl Root {
|
impl Root {
|
||||||
fn date() -> Date {
|
fn date() -> Date {
|
||||||
Date::from_ymd(2015, 3, 14)
|
Date::from_ymd_opt(2015, 3, 14).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_time() -> LocalTime {
|
fn local_time() -> LocalTime {
|
||||||
LocalTime::from_hms(16, 7, 8)
|
LocalTime::from_hms_opt(16, 7, 8).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_date_time() -> LocalDateTime {
|
fn local_date_time() -> LocalDateTime {
|
||||||
LocalDateTime::new(Date::from_ymd(2016, 7, 8), LocalTime::from_hms(9, 10, 11))
|
LocalDateTime::new(
|
||||||
|
Date::from_ymd_opt(2016, 7, 8).unwrap(),
|
||||||
|
LocalTime::from_hms_opt(9, 10, 11).unwrap(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn date_time() -> DateTime<chrono::Utc> {
|
fn date_time() -> DateTime<chrono::Utc> {
|
||||||
DateTime::from_utc(
|
DateTime::from_utc(
|
||||||
LocalDateTime::new(
|
LocalDateTime::new(
|
||||||
Date::from_ymd(1996, 12, 20),
|
Date::from_ymd_opt(1996, 12, 20).unwrap(),
|
||||||
LocalTime::from_hms(0, 39, 57),
|
LocalTime::from_hms_opt(0, 39, 57).unwrap(),
|
||||||
),
|
),
|
||||||
chrono::Utc,
|
chrono::Utc,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue