digraph: double-quote dot graph elements

This commit is contained in:
Mitchell Hashimoto 2014-07-01 09:54:40 -07:00
parent 29d6a4242e
commit 83795bc54d
2 changed files with 11 additions and 11 deletions

View File

@ -11,10 +11,10 @@ func GenerateDot(nodes []Node, w io.Writer) {
w.Write([]byte("digraph {\n"))
defer w.Write([]byte("}\n"))
for _, n := range nodes {
w.Write([]byte(fmt.Sprintf("\t%s;\n", n)))
w.Write([]byte(fmt.Sprintf("\t\"%s\";\n", n)))
for _, edge := range n.Edges() {
target := edge.Tail()
line := fmt.Sprintf("\t%s -> %s [label=\"%s\"];\n",
line := fmt.Sprintf("\t\"%s\" -> \"%s\" [label=\"%s\"];\n",
n, target, edge)
w.Write([]byte(line))
}

View File

@ -27,31 +27,31 @@ b -> e
if !strings.HasSuffix(out, "\n}\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\ta;\n") {
if !strings.Contains(out, "\n\t\"a\";\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\tb;\n") {
if !strings.Contains(out, "\n\t\"b\";\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\tc;\n") {
if !strings.Contains(out, "\n\t\"c\";\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\td;\n") {
if !strings.Contains(out, "\n\t\"d\";\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\te;\n") {
if !strings.Contains(out, "\n\t\"e\";\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\ta -> b [label=\"foo\"];\n") {
if !strings.Contains(out, "\n\t\"a\" -> \"b\" [label=\"foo\"];\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\ta -> c [label=\"Edge\"];\n") {
if !strings.Contains(out, "\n\t\"a\" -> \"c\" [label=\"Edge\"];\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\tb -> d [label=\"Edge\"];\n") {
if !strings.Contains(out, "\n\t\"b\" -> \"d\" [label=\"Edge\"];\n") {
t.Fatalf("bad: %v", out)
}
if !strings.Contains(out, "\n\tb -> e [label=\"Edge\"];\n") {
if !strings.Contains(out, "\n\t\"b\" -> \"e\" [label=\"Edge\"];\n") {
t.Fatalf("bad: %v", out)
}
}