-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_test.go
More file actions
61 lines (54 loc) · 1.44 KB
/
dot_test.go
File metadata and controls
61 lines (54 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package dscope
import (
"strconv"
"strings"
"testing"
)
func TestScopeToDOT(t *testing.T) {
type A int
type B string
type C float64
type D bool
scope := New(
func() A { return 1 },
func(a A) B { return B(strconv.Itoa(int(a))) },
func(a A, b B) C { return C(float64(a) + float64(len(b))) },
).Fork(
func(c C) D { return c > 1.0 }, // Override nothing, add D
).Fork(
func(a A) B { return "overridden" }, // Override B
)
buf := new(strings.Builder)
err := scope.ToDOT(buf)
if err != nil {
t.Fatal(err)
}
dot := buf.String()
t.Log(dot) // Print DOT graph for manual inspection
// Basic checks for presence of types and dependencies
if !strings.Contains(dot, "Defined By: func() dscope.A") {
t.Error("Missing definition info for A")
}
if !strings.Contains(dot, "Defined By: func(dscope.A) dscope.B") { // Check for the *overriding* definition
t.Error("Missing or incorrect definition info for B")
}
if !strings.Contains(dot, "->") { // Check if any edges were generated
t.Error("No dependency edges found in DOT output")
}
if !strings.Contains(dot, "digraph dscope") {
t.Error("DOT output seems invalid")
}
}
func TestToDOTInjectStruct(t *testing.T) {
scope := New(func(inject InjectStruct) int {
return 42
})
buf := new(strings.Builder)
if err := scope.ToDOT(buf); err != nil {
t.Fatal(err)
}
dot := buf.String()
if !strings.Contains(dot, "InjectStruct") {
t.Fatal("InjectStruct missing from DOT graph")
}
}