(t *testing.T)
| 135 | } |
| 136 | |
| 137 | func 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 | |
| 186 | func TestNewDocumentFromResponseNil(t *testing.T) { |
| 187 | r := NewDocumentFromResponse(nil) |
nothing calls this directly
no test coverage detected