MCPcopy
hub / github.com/PuerkitoBio/goquery / TestNodeName

Function TestNodeName

utilities_test.go:27–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25</html>`
26
27func TestNodeName(t *testing.T) {
28 doc, err := NewDocumentFromReader(strings.NewReader(allNodes))
29 if err != nil {
30 t.Fatal(err)
31 }
32
33 n0 := doc.Nodes[0]
34 nDT := n0.FirstChild
35 sMeta := doc.Find("meta")
36 nMeta := sMeta.Get(0)
37 sP := doc.Find("p")
38 nP := sP.Get(0)
39 nComment := nP.FirstChild
40 nText := nComment.NextSibling
41
42 cases := []struct {
43 node *html.Node
44 typ html.NodeType
45 want string
46 }{
47 {n0, html.DocumentNode, nodeNames[html.DocumentNode]},
48 {nDT, html.DoctypeNode, "html"},
49 {nMeta, html.ElementNode, "meta"},
50 {nP, html.ElementNode, "p"},
51 {nComment, html.CommentNode, nodeNames[html.CommentNode]},
52 {nText, html.TextNode, nodeNames[html.TextNode]},
53 }
54 for i, c := range cases {
55 got := NodeName(newSingleSelection(c.node, doc))
56 if c.node.Type != c.typ {
57 t.Errorf("%d: want type %v, got %v", i, c.typ, c.node.Type)
58 }
59 if got != c.want {
60 t.Errorf("%d: want %q, got %q", i, c.want, got)
61 }
62 }
63}
64
65func TestNodeNameMultiSel(t *testing.T) {
66 doc, err := NewDocumentFromReader(strings.NewReader(allNodes))

Callers

nothing calls this directly

Calls 5

NewDocumentFromReaderFunction · 0.85
NodeNameFunction · 0.85
newSingleSelectionFunction · 0.85
FindMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…