Skip to content

Add jsonassert receiver API#11

Merged
nfisher merged 3 commits into
mainfrom
codex/add-assertion-wrapper-structs-and-constructors
Jun 22, 2026
Merged

Add jsonassert receiver API#11
nfisher merged 3 commits into
mainfrom
codex/add-assertion-wrapper-structs-and-constructors

Conversation

@nfisher

@nfisher nfisher commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Motivation

  • Provide typed assertion wrappers so JSON assertions can be invoked via a constructor/receiver API (e.g. jsonassert.String(actual).EqualTo(expected)) for clearer chaining and consistency with other hammy packages.
  • Preserve existing semantic behavior and internal helpers while making the public package-level functions delegate to the new receiver methods.

Description

  • Add wrapper structs StringAssert, BytesAssert, and ReaderAssert and constructors String, Bytes, and Reader in hammy/jsonassert/jsonassert.go to hold the actual value.
  • Implement receiver methods such as (*StringAssert) EqualTo, (*StringAssert) LinesEqualToWithOptions, (*BytesAssert) EqualToWithOptions, (*ReaderAssert) EqualTo, plus IsValid, Contains, PathExists, PathMissing, PathEqual, and array helpers, and delegate the original package-level functions to these methods.
  • Keep internal helper functions like readJSON, linesContain, applyOptions, deleteJSONPath, sortJSONArrayAtPath, containsJSON, path parsing, and number normalization unexported and unchanged as implementation details.
  • Update tests and examples to use the constructor/receiver API and adjust README snippets to show jsonassert.String(...), jsonassert.Bytes(...), and jsonassert.Reader(...) usages.

Testing

  • Ran go test ./hammy/jsonassert and the package tests passed successfully.
  • Ran the full test suite with go test ./... and all packages (including updated examples/tests) passed successfully.

Codex Task

@nfisher nfisher merged commit 0ab8504 into main Jun 22, 2026
1 check passed
@nfisher nfisher deleted the codex/add-assertion-wrapper-structs-and-constructors branch June 22, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant