Skip to content

Commit

Permalink
Port enum_repr tests to new integration test style
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Sep 9, 2024
1 parent 8ea9e25 commit 5b40926
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ chrono04 = { version = "0.4", default-features = false, features = ["serde"], pa
bigdecimal04 = { version = "0.4", default-features = false, features = ["serde"], package = "bigdecimal" }
rust_decimal1 = { version = "1", default-features = false, features = ["serde"], package = "rust_decimal" }
either1 = { version = "1.3", default-features = false, features = ["serde"], package = "either" }
serde_repr = "0.1.19"

[features]
default = ["derive", "std"]
Expand Down
35 changes: 0 additions & 35 deletions schemars/tests/enum_repr.rs

This file was deleted.

37 changes: 37 additions & 0 deletions schemars/tests/integration/enum_repr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::prelude::*;
use schemars::JsonSchema_repr;
use serde_repr::{Deserialize_repr, Serialize_repr};

#[derive(JsonSchema_repr, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
#[serde(rename = "EnumWithReprAttr")]
/// Description from comment
pub enum Enum {
Zero,
One,
Five = 5,
Six,
Three = 3,
}

#[test]
fn enum_repr() {
test!(Enum)
.assert_snapshot()
.assert_allows_ser_roundtrip([Enum::Zero, Enum::One, Enum::Five, Enum::Six, Enum::Three])
.assert_allows_de_roundtrip([
Value::from(0),
Value::from(1),
Value::from(5),
Value::from(6),
Value::from(3),
])
.assert_rejects_de([
Value::from("Zero"),
Value::from("One"),
Value::from("Five"),
Value::from("Six"),
Value::from("Three"),
])
.assert_matches_de_roundtrip(arbitrary_values());
}
1 change: 1 addition & 0 deletions schemars/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod deprecated;
mod docs;
#[cfg(feature = "either1")]
mod either;
mod enum_repr;

mod prelude {
pub use crate::test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Renamed",
"title": "EnumWithReprAttr",
"description": "Description from comment",
"type": "integer",
"enum": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Enum",
"title": "EnumWithReprAttr",
"description": "Description from comment",
"type": "integer",
"enum": [
0,
Expand Down

0 comments on commit 5b40926

Please sign in to comment.