Skip to content

Add field compared/ignored checking to Check.Equality - #60

Merged
AnthonyLloyd merged 5 commits into
masterfrom
equality-fields
Aug 2, 2026
Merged

Add field compared/ignored checking to Check.Equality#60
AnthonyLloyd merged 5 commits into
masterfrom
equality-fields

Conversation

@AnthonyLloyd

Copy link
Copy Markdown
Owner

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 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.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread CsCheck/Check.cs
Comment thread CsCheck/Check.cs
Comment thread CsCheck/Check.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AnthonyLloyd

Copy link
Copy Markdown
Owner Author

@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?

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown

@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 876cdbb.

@AnthonyLloyd

Copy link
Copy Markdown
Owner Author

@copilot can you move Equality_Int in the readme to before the Account type

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown

@copilot can you move Equality_Int in the readme to before the Account type

Done in cdb6c3dEquality_Int is now before the Account type in the README example.

@AnthonyLloyd

Copy link
Copy Markdown
Owner Author

@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?

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown

@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 fe9a2b3.

@AnthonyLloyd
AnthonyLloyd merged commit 9e0e934 into master Aug 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants