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

Function TestOuterHtml

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

Source from the content-addressed store, hash-verified

82}
83
84func TestOuterHtml(t *testing.T) {
85 doc, err := NewDocumentFromReader(strings.NewReader(allNodes))
86 if err != nil {
87 t.Fatal(err)
88 }
89
90 n0 := doc.Nodes[0]
91 nDT := n0.FirstChild
92 sMeta := doc.Find("meta")
93 sP := doc.Find("p")
94 nP := sP.Get(0)
95 nComment := nP.FirstChild
96 nText := nComment.NextSibling
97 sHeaders := doc.Find(".header")
98
99 cases := []struct {
100 node *html.Node
101 sel *Selection
102 want string
103 }{
104 {nDT, nil, "<!DOCTYPE html>"}, // render makes DOCTYPE all caps
105 {nil, sMeta, `<meta a="b"/>`}, // and auto-closes the meta
106 {nil, sP, `<p><!-- this is a comment -->
107 This is some text.
108 </p>`},
109 {nComment, nil, "<!-- this is a comment -->"},
110 {nText, nil, `
111 This is some text.
112 `},
113 {nil, sHeaders, `<h1 class="header"></h1>`},
114 }
115 for i, c := range cases {
116 if c.sel == nil {
117 c.sel = newSingleSelection(c.node, doc)
118 }
119 got, err := OuterHtml(c.sel)
120 if err != nil {
121 t.Fatal(err)
122 }
123
124 if got != c.want {
125 t.Errorf("%d: want %q, got %q", i, c.want, got)
126 }
127 }
128}

Callers

nothing calls this directly

Calls 5

NewDocumentFromReaderFunction · 0.85
newSingleSelectionFunction · 0.85
OuterHtmlFunction · 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…