MCPcopy
hub / github.com/andeya/pholcus / TestNewDocumentFromReader

Function TestNewDocumentFromReader

common/goquery/type_test.go:137–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestNewDocumentFromReader(t *testing.T) {
138 cases := []struct {
139 src string
140 err bool
141 sel string
142 cnt int
143 }{
144 0: {
145 src: `
146<html>
147<head>
148<title>Test</title>
149<body>
150<h1>Hi</h1>
151</body>
152</html>`,
153 sel: "h1",
154 cnt: 1,
155 },
156 1: {
157 // Actually pretty hard to make html.Parse return an error
158 // based on content...
159 src: `<html><body><aef<eqf>>>qq></body></ht>`,
160 },
161 }
162 buf := bytes.NewBuffer(nil)
163
164 for i, c := range cases {
165 buf.Reset()
166 buf.WriteString(c.src)
167
168 r := NewDocumentFromReader(buf)
169 if r.IsErr() != c.err {
170 if c.err {
171 t.Errorf("[%d] - expected error, got none", i)
172 } else {
173 t.Errorf("[%d] - expected no error, got %s", i, r.UnwrapErr())
174 }
175 }
176 if c.sel != "" && !r.IsErr() {
177 d := r.Unwrap()
178 s := d.Find(c.sel)
179 if s.Length() != c.cnt {
180 t.Errorf("[%d] - expected %d nodes, found %d", i, c.cnt, s.Length())
181 }
182 }
183 }
184}
185
186func TestNewDocumentFromResponseNil(t *testing.T) {
187 r := NewDocumentFromResponse(nil)

Callers

nothing calls this directly

Calls 5

NewDocumentFromReaderFunction · 0.85
UnwrapMethod · 0.80
ResetMethod · 0.65
FindMethod · 0.65
LengthMethod · 0.45

Tested by

no test coverage detected