Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions document_value_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package htmlquery

import (
"github.com/antchfx/xpath"
"strings"
"testing"
)

func TestXPathDocumentStringValue(t *testing.T) {
doc, err := Parse(strings.NewReader(`<!DOCTYPE html><html><head><title>A</title></head><body>B<!--excluded--><p>C</p></body></html>`))
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
expr string
want interface{}
}{{`string(/)`, "ABC"}, {`string()`, "ABC"}, {`contains(/, 'BC')`, true}, {`string(//p)`, "C"}, {`string(//comment())`, "excluded"}} {
t.Run(tc.expr, func(t *testing.T) {
got := xpath.MustCompile(tc.expr).Evaluate(CreateXPathNavigator(doc))
if got != tc.want {
t.Errorf("got %#v want %#v", got, tc.want)
}
})
}
}
2 changes: 2 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ func (h *NodeNavigator) Value() string {
return InnerText(h.curr)
case html.TextNode:
return h.curr.Data
case html.DocumentNode:
return InnerText(h.curr)
}
return ""
}
Expand Down