testutil

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package testutil provides shared test helpers for HTML parsing and assertions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAllElements

func FindAllElements(n *html.Node, match func(*html.Node) bool) []*html.Node

FindAllElements returns all nodes matching the predicate.

func FindElement

func FindElement(n *html.Node, match func(*html.Node) bool) *html.Node

FindElement traverses the tree and returns the first node matching the predicate.

func FindElementByClass

func FindElementByClass(n *html.Node, class string) *html.Node

FindElementByClass finds the first element containing the given class.

func FindElementByID

func FindElementByID(n *html.Node, id string) *html.Node

FindElementByID finds an element by its id attribute.

func FindElementByTag

func FindElementByTag(n *html.Node, tag string) *html.Node

FindElementByTag finds the first element with the given tag name.

func GetAttr

func GetAttr(n *html.Node, key string) string

GetAttr returns the value of an attribute, or empty string if not found.

func GetTextContent

func GetTextContent(n *html.Node) string

GetTextContent returns all text content within a node.

func IsDescendant added in v0.5.0

func IsDescendant(ancestor, descendant *html.Node) bool

IsDescendant reports whether descendant is a descendant of ancestor by walking ancestor's subtree. It returns false if either node is nil.

func ParseHTML

func ParseHTML(r io.Reader) (*html.Node, error)

ParseHTML parses an io.Reader into an html.Node.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL