1
0
mirror of https://github.com/golang/go synced 2024-11-25 00:17:58 -07:00

html: dump attributes when running parser tests.

The WebKit test data shows attributes as though they were child nodes:

<a X>0<b>1<a Y>2
dumps as:
| <html>
|   <head>
|   <body>
|     <a>
|       x=""
|       "0"
|       <b>
|         "1"
|     <b>
|       <a>
|         y=""
|         "2"

So we need to do the same when dumping a tree to compare with it.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5322044
This commit is contained in:
Andrew Balholm 2011-10-25 09:33:15 +11:00 committed by Nigel Tao
parent 2b5aa28383
commit 2f3f3aa2ed

View File

@ -69,11 +69,15 @@ func readDat(filename string, c chan io.Reader) {
} }
} }
func dumpLevel(w io.Writer, n *Node, level int) os.Error { func dumpIndent(w io.Writer, level int) {
io.WriteString(w, "| ") io.WriteString(w, "| ")
for i := 0; i < level; i++ { for i := 0; i < level; i++ {
io.WriteString(w, " ") io.WriteString(w, " ")
} }
}
func dumpLevel(w io.Writer, n *Node, level int) os.Error {
dumpIndent(w, level)
switch n.Type { switch n.Type {
case ErrorNode: case ErrorNode:
return os.NewError("unexpected ErrorNode") return os.NewError("unexpected ErrorNode")
@ -81,6 +85,11 @@ func dumpLevel(w io.Writer, n *Node, level int) os.Error {
return os.NewError("unexpected DocumentNode") return os.NewError("unexpected DocumentNode")
case ElementNode: case ElementNode:
fmt.Fprintf(w, "<%s>", n.Data) fmt.Fprintf(w, "<%s>", n.Data)
for _, a := range n.Attr {
io.WriteString(w, "\n")
dumpIndent(w, level+1)
fmt.Fprintf(w, `%s="%s"`, a.Key, a.Val)
}
case TextNode: case TextNode:
fmt.Fprintf(w, "%q", n.Data) fmt.Fprintf(w, "%q", n.Data)
case CommentNode: case CommentNode:
@ -123,7 +132,7 @@ func TestParser(t *testing.T) {
rc := make(chan io.Reader) rc := make(chan io.Reader)
go readDat(filename, rc) go readDat(filename, rc)
// TODO(nigeltao): Process all test cases, not just a subset. // TODO(nigeltao): Process all test cases, not just a subset.
for i := 0; i < 31; i++ { for i := 0; i < 32; i++ {
// Parse the #data section. // Parse the #data section.
b, err := ioutil.ReadAll(<-rc) b, err := ioutil.ReadAll(<-rc)
if err != nil { if err != nil {