Skip to content

Commit

Permalink
Port indexmap tests to new integration test style
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Sep 11, 2024
1 parent 6ec61e8 commit 7183217
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 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.

1 change: 1 addition & 0 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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" }
indexmap2 = { version = "2.0", default-features = false, features = ["serde"], package = "indexmap" }

[features]
default = ["derive", "std"]
Expand Down
19 changes: 19 additions & 0 deletions schemars/tests/integration/indexmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::prelude::*;
use indexmap2::{indexmap, indexset, IndexMap, IndexSet};
use std::collections::{BTreeMap, BTreeSet};

#[test]
fn indexmap() {
test!(IndexMap<String, bool>)
.assert_identical::<BTreeMap<String, bool>>()
.assert_allows_ser_roundtrip([indexmap!(), indexmap!("key".to_owned() => true)])
.assert_matches_de_roundtrip(arbitrary_values());
}

#[test]
fn indexset() {
test!(IndexSet<String>)
.assert_identical::<BTreeSet<String>>()
.assert_allows_ser_roundtrip([indexset!(), indexset!("test".to_owned())])
.assert_matches_de_roundtrip(arbitrary_values());
}
11 changes: 6 additions & 5 deletions schemars/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ mod extend;
mod flatten;
mod from_value;
mod garde;
#[cfg(feature = "indexmap2")]
mod indexmap;
mod std_types;

mod prelude {
Expand All @@ -36,6 +38,7 @@ mod prelude {

mod test_helper;

#[macro_export]
macro_rules! test_name {
() => {{
fn f() {}
Expand All @@ -51,20 +54,18 @@ macro_rules! test_name {
}};
}

#[macro_export]
macro_rules! test {
($type:ty, $settings:expr) => {
$crate::test_helper::TestHelper::<$type>::new(crate::test_name!(), $settings)
$crate::test_helper::TestHelper::<$type>::new($crate::test_name!(), $settings)
};
($type:ty) => {
test!($type, schemars::generate::SchemaSettings::default())
};
(value: $value:expr, $settings:expr) => {
$crate::test_helper::TestHelper::new_for_value(crate::test_name!(), $settings, $value)
$crate::test_helper::TestHelper::new_for_value($crate::test_name!(), $settings, $value)
};
(value: $value:expr) => {
test!(value: $value, schemars::generate::SchemaSettings::default())
};
}

use test;
use test_name;

0 comments on commit 7183217

Please sign in to comment.