Add field compared/ignored checking to Check.Equality - #60
Conversation
Extend Check.Equality with an optional fluent fields builder to verify a type's equality contract at the field level: - Compared fields must change equality; ignored fields must not. - Completeness: any undeclared field that affects equality is detected. - New IEqualityComparer<T> overload to test a comparer directly. - Setters can be functional (record with) or in-place Action; a comparer and/or generator handle fields with normalized equality. - Failures name the field from the setter expression. Add README "Equality testing" section and tests covering compared, ignored, missing, mutable, nested, comparer and normalized cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR extends CsCheck’s Check.Equality support to optionally validate equality at a field level (compared vs ignored fields, plus completeness detection for undeclared fields), adds an IEqualityComparer<T> overload, and documents the new feature with accompanying tests.
Changes:
- Add optional “fields contract” checking to
Check.Equality, including compared/ignored field validation and missing-field detection. - Add an overload to validate an
IEqualityComparer<T>directly using the same consistency and optional field-contract checks. - Add documentation and tests covering compared/ignored/missing fields, mutable setters, nested fields, custom comparers, and normalized equality.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
CsCheck/Check.cs |
Adds field-level equality contract checking, comparer overload, and related helper generators/types. |
Tests/CheckTests.cs |
Adds tests that exercise the new field contract functionality and comparer/normalized cases. |
README.md |
Documents the new “Equality testing” feature and provides examples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot do you think the readme description is good. I like what you put in this PR summary as it was simple. Is the REAME section too wordy? |
I agree it was a bit wordy, so I tightened that section to match the simpler style from the PR summary while keeping the same technical content. Updated in |
|
@copilot can you move Equality_Int in the readme to before the Account type |
Done in |
|
@copilot " if an undeclared field affects equality, it fails and names the field from the setter expression." how does it get a setter if undeclared? |
You’re right — it can’t for undeclared fields. I’ve updated the README to say undeclared-field failures are generic, and setter-expression naming applies to declared fields. Updated in |
Extend Check.Equality with an optional fluent fields builder to verify a type's equality contract at the field level:
Add README "Equality testing" section and tests covering compared, ignored, missing, mutable, nested, comparer and normalized cases.