github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/dag/marshal_test.go (about) 1 package dag 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestGraphDot_empty(t *testing.T) { 9 var g Graph 10 g.Add(1) 11 g.Add(2) 12 g.Add(3) 13 14 actual := strings.TrimSpace(string(g.Dot(nil))) 15 expected := strings.TrimSpace(testGraphDotEmptyStr) 16 if actual != expected { 17 t.Fatalf("bad: %s", actual) 18 } 19 } 20 21 func TestGraphDot_basic(t *testing.T) { 22 var g Graph 23 g.Add(1) 24 g.Add(2) 25 g.Add(3) 26 g.Connect(BasicEdge(1, 3)) 27 28 actual := strings.TrimSpace(string(g.Dot(nil))) 29 expected := strings.TrimSpace(testGraphDotBasicStr) 30 if actual != expected { 31 t.Fatalf("bad: %s", actual) 32 } 33 } 34 35 func TestGraphDot_quoted(t *testing.T) { 36 var g Graph 37 quoted := `name["with-quotes"]` 38 other := `other` 39 g.Add(quoted) 40 g.Add(other) 41 g.Connect(BasicEdge(quoted, other)) 42 43 actual := strings.TrimSpace(string(g.Dot(nil))) 44 expected := strings.TrimSpace(testGraphDotQuotedStr) 45 if actual != expected { 46 t.Fatalf("\ngot: %q\nwanted %q\n", actual, expected) 47 } 48 } 49 50 func TestGraphDot_attrs(t *testing.T) { 51 var g Graph 52 g.Add(&testGraphNodeDotter{ 53 Result: &DotNode{ 54 Name: "foo", 55 Attrs: map[string]string{"foo": "bar"}, 56 }, 57 }) 58 59 actual := strings.TrimSpace(string(g.Dot(nil))) 60 expected := strings.TrimSpace(testGraphDotAttrsStr) 61 if actual != expected { 62 t.Fatalf("bad: %s", actual) 63 } 64 } 65 66 type testGraphNodeDotter struct{ Result *DotNode } 67 68 func (n *testGraphNodeDotter) Name() string { return n.Result.Name } 69 func (n *testGraphNodeDotter) DotNode(string, *DotOpts) *DotNode { return n.Result } 70 71 const testGraphDotQuotedStr = `digraph { 72 compound = "true" 73 newrank = "true" 74 subgraph "root" { 75 "[root] name[\"with-quotes\"]" -> "[root] other" 76 } 77 }` 78 79 const testGraphDotBasicStr = `digraph { 80 compound = "true" 81 newrank = "true" 82 subgraph "root" { 83 "[root] 1" -> "[root] 3" 84 } 85 } 86 ` 87 88 const testGraphDotEmptyStr = `digraph { 89 compound = "true" 90 newrank = "true" 91 subgraph "root" { 92 } 93 }` 94 95 const testGraphDotAttrsStr = `digraph { 96 compound = "true" 97 newrank = "true" 98 subgraph "root" { 99 "[root] foo" [foo = "bar"] 100 } 101 }`