From 2f3f3aa2ed298344f03813214d6b8d486b5f113e Mon Sep 17 00:00:00 2001 From: Andrew Balholm Date: Tue, 25 Oct 2011 09:33:15 +1100 Subject: [PATCH] html: dump attributes when running parser tests. The WebKit test data shows attributes as though they were child nodes: 012 dumps as: | | | | | x="" | "0" | | "1" | | | 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 --- src/pkg/html/parse_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pkg/html/parse_test.go b/src/pkg/html/parse_test.go index 652bf805de9..beba98d3ad2 100644 --- a/src/pkg/html/parse_test.go +++ b/src/pkg/html/parse_test.go @@ -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, "| ") for i := 0; i < level; i++ { io.WriteString(w, " ") } +} + +func dumpLevel(w io.Writer, n *Node, level int) os.Error { + dumpIndent(w, level) switch n.Type { case 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") case ElementNode: 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: fmt.Fprintf(w, "%q", n.Data) case CommentNode: @@ -123,7 +132,7 @@ func TestParser(t *testing.T) { rc := make(chan io.Reader) go readDat(filename, rc) // 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. b, err := ioutil.ReadAll(<-rc) if err != nil {