Skip to content

Commit

Permalink
Added support for nested closures in test name detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 25, 2022
1 parent 758eb6a commit 0b48679
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ macro_rules! _function_name {
fn type_name_of_val<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}
let name = type_name_of_val(f).strip_suffix("::f").unwrap_or("");
name.strip_suffix("::{{closure}}").unwrap_or(name)
let mut name = type_name_of_val(f).strip_suffix("::f").unwrap_or("");
while let Some(rest) = name.strip_suffix("::{{closure}}") {
name = rest;
}
name
}};
}

Expand Down
11 changes: 11 additions & 0 deletions tests/snapshots/test_basic__unnamed_nested_closure.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: tests/test_basic.rs
assertion_line: 22
expression: "vec![1, 2, 3]"

---
[
1,
2,
3,
]
9 changes: 9 additions & 0 deletions tests/test_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ fn test_unnamed_debug_vector() {
assert_debug_snapshot!(vec![1, 2, 3, 4, 5]);
}

#[test]
fn test_unnamed_nested_closure() {
(|| {
(|| {
assert_debug_snapshot!(vec![1, 2, 3]);
})();
})();
}

#[test]
fn test_yaml_vector() {
assert_yaml_snapshot!("yaml_vector", vec![1, 2, 3]);
Expand Down

0 comments on commit 0b48679

Please sign in to comment.