feat: user-defined equality, patch apply, generics, and extensibility - #2
Merged
Merged
Conversation
Honor the exported Equatable[T] and Comparable[T] interfaces (a type's Equals/CompareTo method now decides equality, with custom comparators still taking precedence). Replace the placeholder unified diff with an LCS-based line diff that emits proper context windows and consistent add/remove/context change types. Add field-path and regexp ignores, map key ignores, the `comparator:"-"` struct tag, JSON-tag field naming, a streaming reporter hook, and sentinel errors. FormatDiff now returns ErrUnknownFormat for unknown formats instead of silently using text. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a type-safe generic layer (EqualT, DeepEqualT, DiffT, CompareWithDiffT, GetJSONPatchT). Add context-aware entry points (EqualCtx, DiffCtx, CompareWithDiffCtx and the ContextComparator interface) that stop early on cancellation. Add ApplyJSONPatch, an RFC 6902 applier supporting add/remove/replace/move/copy/test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add RegisterFormatter/UnregisterFormatter so callers can teach FormatDiff new output formats. Add String() helpers for UnifiedDiff and VisualDiff. Add AssertEqual/AssertNotEqual/RequireEqual testing helpers that print a readable diff on failure, using a minimal TestingT interface so the testing package is not pulled into production builds. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add unit tests and executable examples for user-defined equality, unified-diff context, the equate-empty toggle, context cancellation, generics, JSON-tag naming, ApplyJSONPatch round-trips, the reporter hook, richer ignore rules, the formatter registry, diff stringers, and the assertion helpers. Update the format test for the new ErrUnknownFormat contract. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Update the README and docs/ (configuration, diffing, json-patch, custom-comparators, faq) and add extensibility and testing guides covering generics, context, reporters, formatters, patch application, and assertions. Rewrite the AI guidance (copilot-instructions.md) by merging the slashdevops/e5t and ds-utils conventions, tailored to this stdlib-only library, and expose it as AGENTS.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the improvements identified in the API review, turning promised-but-missing behavior into real features and adding high-leverage capabilities. All additions are backward-compatible and remain stdlib-only (zero external dependencies).
What changed
🐞 Correctness / dead code
Equatable[T]/Comparable[T]now work. A type'sEquals(T) boolorCompareTo(T) intmethod is honored automatically (custom comparators still take precedence). They were previously exported and documented but never consulted.add/remove/contextchange types (the old code hard-coded_ = contextSize).WithEquateEmpty(bool)— a real toggle for nil/empty-container equivalence (the oldEquateEmpty()was enable-only).🚀 New capabilities
ApplyJSONPatch— RFC 6902 applier (add/remove/replace/move/copy/test), closing the generate→apply loop.EqualT[T],DeepEqualT[T],DiffT[T],CompareWithDiffT[T],GetJSONPatchT[T].EqualCtx/DiffCtx/CompareWithDiffCtx+ContextComparator, cancellable viacontext.Context.WithFieldNaming(JSONTagNaming)— JSON-tag-aware paths and patch pointers so patches apply to real JSON documents.🔧 Extensibility & ergonomics
WithReporter— stream eachDifferenceas it's found.WithIgnorePaths,WithIgnorePathPatterns(regexp),WithIgnoreMapKeys, and thecomparator:"-"struct tag.RegisterFormatter— pluggable output formats (CSV, JUnit, SARIF, …). Unknown formats now returnErrUnknownFormat.String()helpers forUnifiedDiffandVisualDiff.ErrUnknownFormat,ErrCanceled,ErrInvalidPatch.AssertEqual/AssertNotEqual/RequireEqual(via a minimalTestingTinterface, sotestingisn't pulled into production builds).📖 Docs & AI guidance
docs/and added Extensibility and Testing guides.slashdevops/e5tandds-utilsconventions into.github/copilot-instructions.md, tailored to this stdlib-only library, and exposed it asAGENTS.md(symlink). Ticket-number and no-AI-coauthor rules from ds-utils were intentionally omitted as they don't fit this open-source repo.FormatDiffwith an unknown format now returnsErrUnknownFormatinstead of silently falling back totext. The existing test was updated to assert the new contract.Verification
🤖 Generated with Claude Code