macro_rules! assert_json_matches {
($lhs:expr, $rhs:expr, $config:expr $(,)?) => { ... };
($lhs:expr, $rhs:expr, $config:expr, $($arg:tt)+) => { ... };
}Expand description
Compare two JSON values according to a configuration.
use serde_json_assert::{
CompareMode,
Config,
NumericMode,
assert_json_matches,
};
use serde_json::json;
let config = Config::new(CompareMode::Strict).numeric_mode(NumericMode::AssumeFloat);
assert_json_matches!(
json!({
"a": { "b": [1, 2, 3.0] },
}),
json!({
"a": { "b": [1, 2.0, 3] },
}),
&config,
);
assert_json_matches!(
json!({
"a": { "b": [1, 2, 3.0] },
}),
json!({
"a": { "b": [1, 2.0, 3] },
}),
&config,
"Failed to assert equality between {} and {}",
"lhs",
"rhs"
);When using CompareMode::Inclusive the first argument is actual and the second argument is
expected. Example:
// This
let config = Config::new(CompareMode::Inclusive);
assert_json_matches!(
json!({
"a": { "b": 1 },
}),
json!({
"a": {},
}),
&config,
);
// Is the same as this
assert_json_include!(
actual: json!({
"a": { "b": 1 },
}),
expected: json!({
"a": {},
}),
);