#[cfg(feature = "csv")]
#[macro_export]
macro_rules! assert_csv_snapshot {
($value:expr, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, Csv, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, {$($k => $v),*}, Csv, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, {$($k => $v),*}, Csv);
}};
($name:expr, $value:expr) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, Csv);
}};
($name:expr, $value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, {$($k => $v),*}, Csv);
}};
($value:expr) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, Csv);
}};
}
#[cfg(feature = "toml")]
#[macro_export]
macro_rules! assert_toml_snapshot {
($value:expr, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, Toml, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, {$($k => $v),*}, Toml, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, {$($k => $v),*}, Toml);
}};
($name:expr, $value:expr) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, Toml);
}};
($name:expr, $value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, {$($k => $v),*}, Toml);
}};
($value:expr) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, Toml);
}};
}
#[cfg_attr(feature = "redactions", doc = " ```no_run")]
#[cfg_attr(not(feature = "redactions"), doc = " ```ignore")]
#[macro_export]
macro_rules! assert_yaml_snapshot {
($value:expr, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, Yaml, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, {$($k => $v),*}, Yaml, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, {$($k => $v),*}, Yaml);
}};
($name:expr, $value:expr) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, Yaml);
}};
($name:expr, $value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, {$($k => $v),*}, Yaml);
}};
($value:expr) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, Yaml);
}};
}
#[cfg(feature = "ron")]
#[macro_export]
macro_rules! assert_ron_snapshot {
($value:expr, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, Ron, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, {$($k => $v),*}, Ron, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, {$($k => $v),*}, Ron);
}};
($name:expr, $value:expr) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, Ron);
}};
($name:expr, $value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, {$($k => $v),*}, Ron);
}};
($value:expr) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, Ron);
}};
}
#[macro_export]
macro_rules! assert_json_snapshot {
($value:expr, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, Json, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}, @$snapshot:literal) => {{
$crate::_assert_serialized_snapshot!($value, {$($k => $v),*}, Json, @$snapshot);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, {$($k => $v),*}, Json);
}};
($name:expr, $value:expr) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, Json);
}};
($name:expr, $value:expr, {$($k:expr => $v:expr),*$(,)?}) => {{
$crate::_assert_serialized_snapshot!(Some($name), $value, {$($k => $v),*}, Json);
}};
($value:expr) => {{
$crate::_assert_serialized_snapshot!($crate::_macro_support::AutoName, $value, Json);
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! _assert_serialized_snapshot {
($value:expr, $format:ident, @$snapshot:literal) => {{
let value = $crate::_macro_support::serialize_value(
&$value,
$crate::_macro_support::SerializationFormat::$format,
$crate::_macro_support::SnapshotLocation::Inline
);
$crate::assert_snapshot!(
value,
stringify!($value),
@$snapshot
);
}};
($value:expr, {$($k:expr => $v:expr),*$(,)?}, $format:ident, @$snapshot:literal) => {{
let (vec, value) = $crate::_prepare_snapshot_for_redaction!($value, {$($k => $v),*}, $format, Inline);
$crate::assert_snapshot!(value, stringify!($value), @$snapshot);
}};
($name:expr, $value:expr, $format:ident) => {{
let value = $crate::_macro_support::serialize_value(
&$value,
$crate::_macro_support::SerializationFormat::$format,
$crate::_macro_support::SnapshotLocation::File
);
$crate::assert_snapshot!(
$name,
value,
stringify!($value)
);
}};
($name:expr, $value:expr, {$($k:expr => $v:expr),*$(,)?}, $format:ident) => {{
let (vec, value) = $crate::_prepare_snapshot_for_redaction!($value, {$($k => $v),*}, $format, File);
$crate::assert_snapshot!($name, value, stringify!($value));
}}
}
#[cfg(feature = "redactions")]
#[doc(hidden)]
#[macro_export]
macro_rules! _prepare_snapshot_for_redaction {
($value:expr, {$($k:expr => $v:expr),*$(,)?}, $format:ident, $location:ident) => {
{
let vec = vec![
$((
$crate::_macro_support::Selector::parse($k).unwrap(),
$crate::_macro_support::Redaction::from($v)
),)*
];
let value = $crate::_macro_support::serialize_value_redacted(
&$value,
&vec,
$crate::_macro_support::SerializationFormat::$format,
$crate::_macro_support::SnapshotLocation::$location
);
(vec, value)
}
}
}
#[cfg(not(feature = "redactions"))]
#[doc(hidden)]
#[macro_export]
macro_rules! _prepare_snapshot_for_redaction {
($value:expr, {$($k:expr => $v:expr),*$(,)?}, $format:ident, $location:ident) => {
compile_error!("insta was compiled without redaction support.");
};
}
#[macro_export]
macro_rules! assert_debug_snapshot {
($value:expr, @$snapshot:literal) => {{
let value = format!("{:#?}", $value);
$crate::assert_snapshot!(value, stringify!($value), @$snapshot);
}};
($name:expr, $value:expr) => {{
let value = format!("{:#?}", $value);
$crate::assert_snapshot!(Some($name), value, stringify!($value));
}};
($value:expr) => {{
let value = format!("{:#?}", $value);
$crate::assert_snapshot!($crate::_macro_support::AutoName, value, stringify!($value));
}};
}
#[macro_export]
macro_rules! assert_display_snapshot {
($value:expr, @$snapshot:literal) => {{
let value = format!("{}", $value);
$crate::assert_snapshot!(value, stringify!($value), @$snapshot);
}};
($name:expr, $value:expr) => {{
let value = format!("{}", $value);
$crate::assert_snapshot!(Some($name), value, stringify!($value));
}};
($value:expr) => {{
let value = format!("{}", $value);
$crate::assert_snapshot!($crate::_macro_support::AutoName, value, stringify!($value));
}};
}
#[macro_export]
macro_rules! assert_snapshot {
($value:expr, @$snapshot:literal) => {
$crate::assert_snapshot!(
$crate::_macro_support::ReferenceValue::Inline($snapshot),
$value,
stringify!($value)
)
};
($value:expr, $debug_expr:expr, @$snapshot:literal) => {
$crate::assert_snapshot!(
$crate::_macro_support::ReferenceValue::Inline($snapshot),
$value,
$debug_expr
)
};
($name:expr, $value:expr) => {
$crate::assert_snapshot!($name, $value, stringify!($value))
};
($name:expr, $value:expr, $debug_expr:expr) => {
$crate::_macro_support::assert_snapshot(
$name.into(),
&$value,
env!("CARGO_MANIFEST_DIR"),
module_path!(),
file!(),
line!(),
$debug_expr,
)
.unwrap();
};
($value:expr) => {
$crate::assert_snapshot!($crate::_macro_support::AutoName, $value, stringify!($value))
};
}
#[macro_export]
macro_rules! with_settings {
({$($k:ident => $v:expr),*$(,)?}, $body:block) => {{
let mut settings = $crate::Settings::new();
$(
settings._private_inner_mut().$k = $v.into();
)*
settings.bind(|| $body)
}}
}
#[cfg(feature = "glob")]
#[macro_export]
macro_rules! glob {
($glob:expr, $closure:expr) => {{
let base = $crate::_macro_support::get_cargo_workspace(env!("CARGO_MANIFEST_DIR"))
.join(file!())
.parent()
.unwrap()
.canonicalize()
.unwrap_or_else(|e| panic!("failed to canonicalize insta::glob! base path: {}", e));
$crate::_macro_support::glob_exec(&base, $glob, $closure);
}};
}