2014-05-24 21:47:04 +02:00
|
|
|
package digraph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_GenerateDot(t *testing.T) {
|
|
|
|
nodes := ParseBasic(`a -> b ; foo
|
|
|
|
a -> c
|
|
|
|
b -> d
|
|
|
|
b -> e
|
|
|
|
`)
|
|
|
|
var nlist []Node
|
|
|
|
for _, n := range nodes {
|
|
|
|
nlist = append(nlist, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
GenerateDot(nlist, buf)
|
|
|
|
|
|
|
|
out := string(buf.Bytes())
|
|
|
|
if !strings.HasPrefix(out, "digraph {\n") {
|
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
|
|
|
if !strings.HasSuffix(out, "\n}\n") {
|
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"a\";\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"b\";\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"c\";\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"d\";\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"e\";\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"a\" -> \"b\" [label=\"foo\"];\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"a\" -> \"c\" [label=\"Edge\"];\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"b\" -> \"d\" [label=\"Edge\"];\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
2014-07-01 18:54:40 +02:00
|
|
|
if !strings.Contains(out, "\n\t\"b\" -> \"e\" [label=\"Edge\"];\n") {
|
2014-05-24 21:47:04 +02:00
|
|
|
t.Fatalf("bad: %v", out)
|
|
|
|
}
|
|
|
|
}
|