Skip to content

Add hammy/htmlassert package for semantic HTML assertions - #15

Merged
nfisher merged 11 commits into
mainfrom
codex/create-htmlassert-package-with-html-assertions
Sep 8, 2026
Merged

nfisher merged 11 commits into
mainfrom
codex/create-htmlassert-package-with-html-assertions

Conversation

@nfisher

@nfisher nfisher commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Motivation

  • Provide a focused API for semantic HTML assertions (DOM structure, selectors, text, and attributes) to complement existing httpassert, jsonassert, and yamlassert packages.
  • Use a standards-compliant HTML5 parser and CSS selector engine rather than ad-hoc parsing to avoid brittle string comparisons and selector handling.
  • Keep selector handling small and correct by pinning github.com/andybalholm/cascadia and reusing golang.org/x/net/html for parsing.

Description

  • Add a new package hammy/htmlassert implementing String, Bytes, and Reader wrappers and assertions including EqualTo, HasSelector, NoSelector, SelectorCount, TextEqualTo, TextContains, AttributeEqualTo, HasAttribute, NoAttribute, and Contains.
  • Implement semantic canonicalization and structural containment checks for HTML using golang.org/x/net/html and CSS selector matching via github.com/andybalholm/cascadia.
  • Add tests in hammy/htmlassert/htmlassert_test.go that exercise document equality, selector queries, text/attribute assertions, fragment containment, and reader/byte variants, and add an example in hammy/htmlassert/example_test.go.
  • Update go.mod to add github.com/andybalholm/cascadia and golang.org/x/net dependencies and update README.md and hammy/README.md with usage examples and package description.

Testing

  • Ran unit tests for the new package with go test ./hammy/htmlassert, which executed htmlassert_test.go and the example, and all tests passed.
  • Ran repository-wide tests with go test ./... and no test failures were reported for the modified code paths.

Codex Task

@nfisher
nfisher enabled auto-merge (squash) September 8, 2026 21:29
@nfisher
nfisher merged commit 9e852e6 into main Sep 8, 2026
1 check passed
@nfisher
nfisher deleted the codex/create-htmlassert-package-with-html-assertions branch September 8, 2026 21:30
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