Skip to content

v1.2.1 - extended equalTo descriptions

Latest

Choose a tag to compare

@corbym corbym released this 22 Apr 21:19
d0060d0

Whats changed

*is/equalto.go — Added diffDescription recursive helper and wired it into EqualTo:

On a mismatch, match.Actual is populated with a breadcrumb-style diff (e.g. .Name: expected , got ) which then.AssertThat already uses in its "but:" output line.

  • Structs: iterates exported fields, recurses into any that differ, producing paths like .FieldName.
    Slices/Arrays: iterates indices up to the longer length, producing paths like [0], reporting for extra/absent elements.

  • Maps: uses direct MapIndex lookups (O(n) per key, no string-key collisions), sorts diffs alphabetically for deterministic output, producing paths like [key].
    Kind guards on each branch prevent panics when the underlying types don't match (possible with any-typed generics).

  • Pointer dereferencing only proceeds when both sides are pointers simultaneously.
    Falls back to plain %v for primitives or unhandled kinds.
    matcher_test.go — Added TestEqualToStructShowsDiffOnFailure covering three sub-cases: struct field diff, slice index diff, and map key diff — each asserting that the failure output contains the path/key name plus both expected and actual values.

  • Fix and expand README matcher documentation by @Copilot in #16

  • Remove dead kind-mismatch guards from diffDescription by @Copilot in #17

Full Changelog: v1.2.0...v1.2.1