Skip to content

Commit

Permalink
Allow unnamed snapshots to compile (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored and mitsuhiko committed Jul 19, 2019
1 parent d5d7f85 commit aef5207
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "insta"
version = "0.8.1"
version = "0.8.2"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
Expand Down
40 changes: 14 additions & 26 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,47 +283,35 @@ macro_rules! assert_display_snapshot_matches {
#[macro_export]
macro_rules! assert_snapshot_matches {
($value:expr, @$snapshot:literal) => {
$crate::_assert_snapshot_matches!(
$crate::assert_snapshot_matches!(
$crate::_macro_support::ReferenceValue::Inline($snapshot),
$value,
stringify!($value)
)
};
($value:expr, $debug_expr:expr, @$snapshot:literal) => {
$crate::_assert_snapshot_matches!(
$crate::assert_snapshot_matches!(
$crate::_macro_support::ReferenceValue::Inline($snapshot),
$value,
$debug_expr
)
};
($name:expr, $value:expr) => {
$crate::_assert_snapshot_matches!(From::from($name), $value, stringify!($value))
$crate::assert_snapshot_matches!($name, $value, stringify!($value))
};
($name:expr, $value:expr, $debug_expr:expr) => {
$crate::_assert_snapshot_matches!(From::from($name), $value, $debug_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_matches!(None::<String>, $value, stringify!($value))
};
}

#[doc(hidden)]
#[macro_export]
macro_rules! _assert_snapshot_matches {
($refval:expr, $value:expr, $debug_expr:expr) => {
match &$value {
value => {
$crate::_macro_support::assert_snapshot(
$refval,
value,
env!("CARGO_MANIFEST_DIR"),
module_path!(),
file!(),
line!(),
$debug_expr,
)
.unwrap();
}
}
$crate::assert_snapshot_matches!(None::<String>, $value, stringify!($value))
};
}
7 changes: 7 additions & 0 deletions tests/snapshots/test_inline__unnamed_single_line-2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
created: "2019-07-16T10:35:19.553505Z"
creator: insta@0.8.1
source: tests/test_inline.rs
expression: "\"Testing-2\""
---
Testing-2
7 changes: 7 additions & 0 deletions tests/snapshots/test_inline__unnamed_single_line.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
created: "2019-07-16T10:31:50.245097Z"
creator: insta@0.8.1
source: tests/test_inline.rs
expression: "\"Testing\""
---
Testing
6 changes: 6 additions & 0 deletions tests/test_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ fn test_single_line() {
assert_snapshot_matches!("Testing", @"Testing");
}

#[test]
fn test_unnamed_single_line() {
assert_snapshot_matches!("Testing");
assert_snapshot_matches!("Testing-2");
}

#[test]
fn test_ron_inline() {
#[derive(Serialize)]
Expand Down

0 comments on commit aef5207

Please sign in to comment.