Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualize child scopes #403

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion visualize.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,19 @@ func (c *Container) createGraph() *dot.Graph {
func (s *Scope) createGraph() *dot.Graph {
dg := dot.NewGraph()

s.addNodes(dg)

return dg
}

func (s *Scope) addNodes(dg *dot.Graph) {
for _, n := range s.nodes {
dg.AddCtor(newDotCtor(n), n.paramList.DotParam(), n.resultList.DotResult())
}

return dg
for _, cs := range s.childScopes {
cs.addNodes(dg)
}
}

func newDotCtor(n *constructorNode) *dot.Ctor {
Expand Down
58 changes: 57 additions & 1 deletion visualize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestDotGraph(t *testing.T) {
assertCtorsEqual(t, expected, dg.Ctors)
})

t.Run("create graph with multple constructors", func(t *testing.T) {
t.Run("create graph with multiple constructors", func(t *testing.T) {
expected := []*dot.Ctor{
{
Params: []*dot.Param{p1},
Expand All @@ -141,6 +141,62 @@ func TestDotGraph(t *testing.T) {
assertCtorsEqual(t, expected, dg.Ctors)
})

t.Run("create graph with scope", func(t *testing.T) {
expected := []*dot.Ctor{
{
Params: []*dot.Param{p1},
Results: []*dot.Result{r2},
},
{
Params: []*dot.Param{p1},
Results: []*dot.Result{r3},
},
{
Params: []*dot.Param{p2},
Results: []*dot.Result{r4},
},
}

c := digtest.New(t)
c.Provide(func(A t1) t2 { return t2{} })

s := c.Scope("test")
s.Provide(func(A t1) t3 { return t3{} })
s.Provide(func(A t2) t4 { return t4{} })

dg := c.CreateGraph()
assertCtorsEqual(t, expected, dg.Ctors)
})

t.Run("create graph with child scope", func(t *testing.T) {
expected := []*dot.Ctor{
{
Params: []*dot.Param{p1},
Results: []*dot.Result{r2},
},
{
Params: []*dot.Param{p1},
Results: []*dot.Result{r3},
},
{
Params: []*dot.Param{p2},
Results: []*dot.Result{r4},
},
}

c := digtest.New(t)
c.Provide(func(A t1) t2 { return t2{} })

s := c.Scope("parent_scope")
s.Provide(func(A t1) t3 { return t3{} })

cs := s.Scope("child_scope")
cs.Provide(func(A t2) t4 { return t4{} })

dg := c.CreateGraph()
assertCtorsEqual(t, expected, dg.Ctors)
})

t.Run("constructor with multiple params and results", func(t *testing.T) {
expected := []*dot.Ctor{
{
Expand Down
Loading