Skip to content

Commit

Permalink
Port chrono test to new integration test style
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Sep 8, 2024
1 parent 837464c commit 7ed11f9
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 27 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ serde = { version = "1.0", features = ["derive"] }
jsonschema = { version = "0.18.1", default-features = false }
snapbox = { version = "0.6.17", features = ["json"] }

arrayvec07 = { version = "0.7", features = ["serde"], package = "arrayvec"}
bytes1 = { version = "1.0", features = ["serde"], package = "bytes" }
arrayvec07 = { version = "0.7", default-features = false, features = ["serde"], package = "arrayvec"}
bytes1 = { version = "1.0", default-features = false, features = ["serde"], package = "bytes" }
chrono04 = { version = "0.4", default-features = false, features = ["serde"], package = "chrono" }

[features]
default = ["derive", "std"]
Expand Down Expand Up @@ -77,10 +78,6 @@ required-features = ["std"]
name = "ui"
required-features = ["_ui_test"]

[[test]]
name = "chrono"
required-features = ["chrono04"]

[[test]]
name = "indexmap"
required-features = ["indexmap2"]
Expand Down
2 changes: 1 addition & 1 deletion schemars/src/json_schema_impls/chrono04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ macro_rules! formatted_string_impl {

formatted_string_impl!(NaiveDate, "date");
formatted_string_impl!(NaiveDateTime, "partial-date-time");
formatted_string_impl!(NaiveTime, "partial-date-time");
formatted_string_impl!(NaiveTime, "partial-time");
formatted_string_impl!(DateTime, "date-time", <Tz: TimeZone> JsonSchema for DateTime<Tz>);
19 changes: 0 additions & 19 deletions schemars/tests/chrono.rs

This file was deleted.

42 changes: 42 additions & 0 deletions schemars/tests/integration/chrono.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::prelude::*;
use chrono04::prelude::*;

#[derive(JsonSchema, Serialize, Deserialize)]
struct ChronoTypes {
weekday: Weekday,
date_time: DateTime<Utc>,
naive_date: NaiveDate,
naive_date_time: NaiveDateTime,
naive_time: NaiveTime,
}

#[test]
fn chrono() {
test!(ChronoTypes).assert_snapshot();

test!(Weekday)
.assert_allows_ser_roundtrip([Weekday::Mon])
.assert_matches_de_roundtrip(arbitrary_values());

test!(DateTime<Utc>)
.assert_allows_ser_roundtrip_default()
.assert_matches_de_roundtrip(arbitrary_values());

test!(NaiveDate)
.assert_allows_ser_roundtrip_default()
.assert_matches_de_roundtrip(arbitrary_values());

test!(NaiveDateTime)
.assert_allows_ser_roundtrip_default()
.assert_matches_de_roundtrip(arbitrary_values_except(
Value::is_string,
"Custom format 'partial-date-time', so arbitrary strings technically allowed by schema",
));

test!(NaiveTime)
.assert_allows_ser_roundtrip_default()
.assert_matches_de_roundtrip(arbitrary_values_except(
Value::is_string,
"Custom format 'date-time', so arbitrary strings technically allowed by schema",
));
}
2 changes: 2 additions & 0 deletions schemars/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ mod arrayvec;
mod bound;
#[cfg(feature = "bytes1")]
mod bytes;
#[cfg(feature = "chrono04")]
mod chrono;

mod prelude {
pub use crate::test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"naive_time": {
"type": "string",
"format": "partial-date-time"
"format": "partial-time"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ChronoTypes",
"type": "object",
"properties": {
"weekday": {
"type": "string",
"enum": [
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun"
]
},
"date_time": {
"type": "string",
"format": "date-time"
},
"naive_date": {
"type": "string",
"format": "date"
},
"naive_date_time": {
"type": "string",
"format": "partial-date-time"
},
"naive_time": {
"type": "string",
"format": "partial-time"
}
},
"required": [
"weekday",
"date_time",
"naive_date",
"naive_date_time",
"naive_time"
]
}

0 comments on commit 7ed11f9

Please sign in to comment.