Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
NotEmpty: [
TheValue
]
}
17 changes: 17 additions & 0 deletions src/Verify.Tests/Serialization/IgnoreInstanceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class IgnoreInstanceTests
{
[Fact]
public Task NonMatchingPredicateKeepsEmptyCollectionsIgnored() =>
Verify(
new
{
Empty = new List<string>(),
NotEmpty = new List<string>
{
"TheValue"
}
})
// a predicate that never matches is not a decision to keep the value,
// so Empty is still ignored as an empty collection
.IgnoreInstance<List<string>>(_ => false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ internal bool TryGetScrubOrIgnore(Type declaringType, Type memberType, string na
internal bool TryGetScrubOrIgnoreByInstance(object value, [NotNullWhen(true)] out ScrubOrIgnore? scrubOrIgnore)
{
var memberType = value.GetType();
// no predicate matching is not a decision to keep the value, so
// the empty collection check still applies
if (GetShouldIgnoreInstance(memberType, out var funcs))
{
foreach (var func in funcs)
Expand All @@ -34,9 +36,6 @@ internal bool TryGetScrubOrIgnoreByInstance(object value, [NotNullWhen(true)] ou
return true;
}
}

scrubOrIgnore = null;
return false;
}

if (ignoreEmptyCollections &&
Expand Down
2 changes: 1 addition & 1 deletion src/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ All six resolved 2026-08-16 (five fixed here; the inline item resolved as by-des
- [ ] **`MemberConverter` has no exact-type precedence.**
`Verify/Serialization/VerifierSettings_MemberConverter.cs:13-25` — first registered entry with `IsAssignableFrom` wins, so a base-interface converter registered earlier permanently shadows a more specific one. Contrast `TryGetScrubOrIgnoreByMemberOfType`, which checks the exact declaring type first.

- [ ] **Registering an `IgnoreInstance` predicate disables empty-collection ignoring for that type.**
- [x] **Registering an `IgnoreInstance` predicate disables empty-collection ignoring for that type.**
`Verify/Serialization/SerializationSettings_ShouldIgnore.cs:26-40` — when predicates exist but none match, the early `return false` skips the `ignoreEmptyCollections` check at 42-47. An empty `List<string>` starts appearing as `[]` merely because an unrelated predicate was registered.

- [x] **Combinations name cache collapses distinct keys.**
Expand Down
Loading