htmlcheck

package
v0.0.0-...-41da83f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package htmlcheck provides a set of functions that check for properties of a parsed HTML document.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(reader io.Reader, checker Checker) error

Run is a convenience function to run the checker against HTML read from reader.

Types

type Checker

type Checker func(*html.Node) error

A Checker is a function from an HTML node to an error describing a failure.

func Dump

func Dump() Checker

Dump returns a Checker that always returns nil, and as a side-effect writes a human-readable description of n's subtree to standard output. It is useful for debugging.

func HasAttr

func HasAttr(name, wantValRegexp string) Checker

HasAttr returns a Checker that checks for an attribute with the given name whose value matches the given regular expression. HasAttr panics if wantValRegexp does not compile.

func HasExactText

func HasExactText(want string) Checker

HasExactText returns a checker that checks whether the given string matches the node's text exactly.

func HasExactTextCollapsed

func HasExactTextCollapsed(want string) Checker

HasExactTextCollapsed returns a checker that checks whether the given string matches the node's text with its leading, trailing, and redundant whitespace trimmed.

func HasHref

func HasHref(val string) Checker

HasHref returns a Checker that checks whether the node has an "href" attribute with exactly val.

func HasText

func HasText(wantRegexp string) Checker

HasText returns a Checker that checks whether the given regexp matches the node's text. The text of a node n is the concatenated contents of all text nodes in n's subtree. HasText panics if the argument doesn't compile.

func In

func In(selector string, checkers ...Checker) Checker

In returns a Checker that applies the given checkers to the first node matching the CSS selector. The empty selector denotes the entire subtree of the Checker's argument node.

Calling In(selector), with no checkers, just checks for the presence of a node matching the selector. (For the negation, see NotIn.)

A nil Checker is valid and always succeeds.

func NotIn

func NotIn(selector string) Checker

NotIn returns a checker that succeeds only if no nodes match selector.

Jump to

Keyboard shortcuts

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