blob: acbdb67237c4a7575e7b6f2cf2d7e1107c85a396 [file] [log] [blame]
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package htmlcheck
import (
"strings"
"testing"
"golang.org/x/net/html"
)
func Test(t *testing.T) {
const data = `
<html>
<div id="ID" class="CLASS1 CLASS2">
BEFORE <a href="HREF">DURING</a> AFTER
</div>
</html>`
doc, err := html.Parse(strings.NewReader(data))
if err != nil {
t.Fatal(err)
}
for _, test := range []struct {
name string
checker Checker
}{
{
"In",
In("div.CLASS1",
HasText(`^\s*BEFORE DURING AFTER\s*$`),
HasAttr("id", "ID"),
HasAttr("class", `\bCLASS2\b`)),
},
{
"a",
In("a", HasAttr("href", "^HREF$"), HasText("DURING")),
},
{
"NotIn",
NotIn("#foo"),
},
} {
got := test.checker(doc)
if got != nil {
t.Errorf("%s: failed with %v", test.name, got)
}
}
}