Skip to content

Commit

Permalink
Port rust_decimal/bigdecimal tests 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 4aeda95 commit 3823b8a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

8 changes: 3 additions & 5 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ chrono04 = { version = "0.4", default-features = false, optional = true, package
either1 = { version = "1.3", default-features = false, optional = true, package = "either" }
enumset1 = { version = "1.0", default-features = false, optional = true, package = "enumset" }
indexmap2 = { version = "2.0", default-features = false, optional = true, package = "indexmap" }
rust_decimal1 = { version = "1", default-features = false, optional = true, package = "rust_decimal"}
rust_decimal1 = { version = "1", default-features = false, optional = true, package = "rust_decimal" }
semver1 = { version = "1.0.9", default-features = false, optional = true, package = "semver" }
smallvec1 = { version = "1.0", default-features = false, optional = true, package = "smallvec" }
smol_str02 = { version = "0.2.1", default-features = false, optional = true, package = "smol_str" }
Expand All @@ -44,6 +44,8 @@ snapbox = { version = "0.6.17", features = ["json"] }
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" }
bigdecimal04 = { version = "0.4", default-features = false, features = ["serde"], package = "bigdecimal" }
rust_decimal1 = { version = "1", default-features = false, features = ["serde"], package = "rust_decimal" }

[features]
default = ["derive", "std"]
Expand Down Expand Up @@ -110,10 +112,6 @@ required-features = ["smol_str02"]
name = "semver"
required-features = ["semver1"]

[[test]]
name = "decimal"
required-features = ["rust_decimal1", "bigdecimal04"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--extend-css", "docs-rs-custom.css"]
12 changes: 0 additions & 12 deletions schemars/tests/decimal.rs

This file was deleted.

9 changes: 0 additions & 9 deletions schemars/tests/expected/rust_decimal.json

This file was deleted.

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

#[test]
fn decimal_types() {
#[cfg(feature = "rust_decimal1")]
test!(rust_decimal1::Decimal)
.assert_snapshot()
.assert_allows_ser_roundtrip_default()
.assert_matches_de_roundtrip(arbitrary_values());

#[cfg(feature = "bigdecimal04")]
test!(bigdecimal04::BigDecimal)
.assert_snapshot()
.assert_allows_ser_roundtrip_default()
.assert_matches_de_roundtrip(arbitrary_values());

#[cfg(all(feature = "rust_decimal1", feature = "bigdecimal04"))]
test!(bigdecimal04::BigDecimal).assert_identical::<rust_decimal1::Decimal>();
}
2 changes: 2 additions & 0 deletions schemars/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ mod bytes;
mod chrono;
mod contract;
mod crate_alias;
#[cfg(any(feature = "rust_decimal1", feature = "bigdecimal04"))]
mod decimal;

mod prelude {
pub use crate::test;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Decimal",
"type": "string",
"pattern": "^-?[0-9]+(\\.[0-9]+)?$"
}
10 changes: 6 additions & 4 deletions schemars/tests/integration/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ impl<T: JsonSchema> TestHelper<T> {
let de_path = format!("tests/integration/snapshots/{}.de.json", self.name);
snapbox::assert_data_eq!(
self.de_schema().into_json(),
snapbox::Data::read_from(Path::new(&de_path), None)
snapbox::Data::read_from(Path::new(&de_path), None).raw()
);

let ser_path = format!("tests/integration/snapshots/{}.ser.json", self.name);
snapbox::assert_data_eq!(
self.ser_schema().into_json(),
snapbox::Data::read_from(Path::new(&ser_path), None)
snapbox::Data::read_from(Path::new(&ser_path), None).raw()
);

self
Expand All @@ -59,11 +59,13 @@ impl<T: JsonSchema> TestHelper<T> {
pub fn assert_identical<T2: JsonSchema>(&self) -> &Self {
snapbox::assert_data_eq!(
self.de_schema().into_json(),
self.schema_for::<T2>(Contract::Deserialize).into_json()
self.schema_for::<T2>(Contract::Deserialize)
.into_json()
.raw()
);
snapbox::assert_data_eq!(
self.ser_schema().into_json(),
self.schema_for::<T2>(Contract::Serialize).into_json()
self.schema_for::<T2>(Contract::Serialize).into_json().raw()
);
let t = type_name::<T>();
let t2 = type_name::<T2>();
Expand Down

0 comments on commit 3823b8a

Please sign in to comment.