MCPcopy Create free account
hub / github.com/antchfx/htmlquery / TestXPath

Function TestXPath

query_test.go:146–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func TestXPath(t *testing.T) {
147 node := FindOne(testDoc, "//html")
148 if SelectAttr(node, "lang") != "en-US" {
149 t.Fatal("//html[@lang] != en-Us")
150 }
151
152 node = FindOne(testDoc, "//header")
153 if strings.Index(InnerText(node), "Logo") > 0 {
154 t.Fatal("InnerText() have comment node text")
155 }
156 if !strings.Contains(OutputHTML(node, true), "Logo") {
157 t.Fatal("OutputHTML() shoud have comment node text")
158 }
159 link := FindOne(testDoc, "//a[1]/@href")
160 if link == nil {
161 t.Fatal("link is nil")
162 }
163 if v := InnerText(link); v != "/London" {
164 t.Fatalf("expect value is /London, but got %s", v)
165 }
166
167}
168
169func TestXPathCdUp(t *testing.T) {
170 doc := loadHTML(`<html><b attr="1"></b></html>`)

Callers

nothing calls this directly

Calls 4

FindOneFunction · 0.85
SelectAttrFunction · 0.85
InnerTextFunction · 0.85
OutputHTMLFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…