github.com/jonasi/terraform@v0.6.10-0.20160125170522-e865c342cc1f/digraph/basic_test.go (about) 1 package digraph 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestParseBasic(t *testing.T) { 9 spec := `a -> b ; first 10 b -> c ; second 11 b -> d ; third 12 z -> a` 13 nodes := ParseBasic(spec) 14 if len(nodes) != 5 { 15 t.Fatalf("bad: %v", nodes) 16 } 17 18 a := nodes["a"] 19 if a.Name != "a" { 20 t.Fatalf("bad: %v", a) 21 } 22 aEdges := a.Edges() 23 if len(aEdges) != 1 { 24 t.Fatalf("bad: %v", a.Edges()) 25 } 26 if fmt.Sprintf("%v", aEdges[0]) != "first" { 27 t.Fatalf("bad: %v", aEdges[0]) 28 } 29 30 b := nodes["b"] 31 if len(b.Edges()) != 2 { 32 t.Fatalf("bad: %v", b.Edges()) 33 } 34 35 c := nodes["c"] 36 if len(c.Edges()) != 0 { 37 t.Fatalf("bad: %v", c.Edges()) 38 } 39 40 d := nodes["d"] 41 if len(d.Edges()) != 0 { 42 t.Fatalf("bad: %v", d.Edges()) 43 } 44 45 z := nodes["z"] 46 zEdges := z.Edges() 47 if len(zEdges) != 1 { 48 t.Fatalf("bad: %v", z.Edges()) 49 } 50 if fmt.Sprintf("%v", zEdges[0]) != "Edge" { 51 t.Fatalf("bad: %v", zEdges[0]) 52 } 53 }