Skip to content

Commit

Permalink
Port skip tests to new integration test style
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Sep 15, 2024
1 parent f17d3d6 commit 5ae8cdd
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 105 deletions.
25 changes: 0 additions & 25 deletions schemars/tests/expected/skip_enum_variants.json

This file was deleted.

17 changes: 0 additions & 17 deletions schemars/tests/expected/skip_tuple_fields.json

This file was deleted.

1 change: 1 addition & 0 deletions schemars/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod schema_with;
#[cfg(feature = "semver1")]
mod semver;
mod settings;
mod skip;
#[cfg(feature = "smallvec1")]
mod smallvec;
#[cfg(feature = "smol_str02")]
Expand Down
41 changes: 41 additions & 0 deletions schemars/tests/integration/skip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::prelude::*;

#[derive(JsonSchema, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
struct Struct {
#[serde(skip)]
_skipped: bool,
included: bool,
}

#[test]
fn skip_struct_field() {
test!(Struct)
.assert_snapshot()
.assert_allows_de_roundtrip([json!({ "included": true })])
.assert_rejects_de([json!({
"_skipped": true,
"included": true
})])
.assert_matches_de_roundtrip(arbitrary_values_except(
Value::is_array,
"structs with `#derive(Deserialize)` can technically be deserialized from sequences, but that's not intended to be used via JSON, so schemars ignores it",
));
}

#[derive(JsonSchema, Deserialize, Serialize)]
pub enum Enum {
Included1,
#[serde(skip)]
_Skipped,
Included2,
}

#[test]
fn skip_enum_variants() {
test!(Enum)
.assert_snapshot()
.assert_allows_de_roundtrip([json!("Included1"), json!("Included2")])
.assert_rejects_de([json!("_Skipped")])
.assert_matches_de_roundtrip(arbitrary_values());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Enum",
"type": "string",
"enum": [
"Included1",
"Included2"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Enum",
"type": "string",
"enum": [
"Included1",
"Included2"
]
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "MyStruct",
"title": "Struct",
"type": "object",
"properties": {
"writable": {
"type": "number",
"format": "float",
"writeOnly": true
},
"included": {
"type": "null"
"type": "boolean"
}
},
"additionalProperties": false,
"required": [
"writable",
"included"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct",
"type": "object",
"properties": {
"included": {
"type": "boolean"
}
},
"additionalProperties": false,
"required": [
"included"
]
}
55 changes: 0 additions & 55 deletions schemars/tests/skip.rs

This file was deleted.

0 comments on commit 5ae8cdd

Please sign in to comment.