package getelementbyid
import (
"golang.org/x/net/html"
"strings"
"testing"
)
const indexHtml = `
[Go] HTML table to reStructuredText list-table
R1, C1 | R1, C2 |
R2, C1 | R2, C2 |
`
func TestTable2Rst(t *testing.T) {
doc, err := html.Parse(strings.NewReader(indexHtml))
if err != nil {
panic("Fail to parse!")
}
r1 := getElementById(doc, "foo")
if r1.Data != "td" || r1.FirstChild.Data != "R1, C1" {
t.Error("wrong element whose id is foo")
}
r2 := getElementById(doc, "foo2")
if r2 != nil {
t.Error("foo2 should not exist!")
}
}