Skip to content

Commit

Permalink
Merge pull request #7 from tchssk/expr-container-test
Browse files Browse the repository at this point in the history
Add tests for expr.Container(s)
  • Loading branch information
raphael authored Nov 1, 2020
2 parents 1a0f9ef + d09fc0c commit 246eebf
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions expr/container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package expr

import (
"fmt"
"testing"
)

func TestContainerEvalName(t *testing.T) {
t.Parallel()
tests := []struct {
name, want string
}{
{name: "", want: "unnamed container"},
{name: "foo", want: `container "foo"`},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
container := Container{
Element: &Element{
Name: tt.name,
},
}
if got := container.EvalName(); got != tt.want {
t.Errorf("got %s, want %s", got, tt.want)
}
})
}
}

func TestContainerFinalize(t *testing.T) {
t.Parallel()
container := Container{
Element: &Element{
Name: "foo",
},
}
tests := []struct {
pre func()
want string
}{
{want: ""},
{pre: func() { container.Tags = "foo" }, want: "foo"},
{pre: func() { container.Finalize() }, want: "Element,Container,foo"},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprint(i), func(t *testing.T) {
if tt.pre != nil {
tt.pre()
}
if got := container.Tags; got != tt.want {
t.Errorf("got %s, want %s", got, tt.want)
}
})
}
}

func TestContainersElements(t *testing.T) {
t.Parallel()
containers := Containers{
{Element: &Element{Name: "foo"}},
{Element: &Element{Name: "bar"}},
{Element: &Element{Name: "baz"}},
}
if got := containers.Elements(); len(got) != len(containers) {
t.Errorf("got %d, want %d", len(got), len(containers))
}
}

func TestContainerComponent(t *testing.T) {
t.Parallel()
container := Container{
Components: Components{
{Element: &Element{Name: "foo"}},
{Element: &Element{Name: "bar"}},
{Element: &Element{Name: "baz"}},
},
}
tests := []struct {
name string
want *Component
}{
{name: "thud", want: nil},
{name: "bar", want: container.Components[1]},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprint(i), func(t *testing.T) {
if got := container.Component(tt.name); got != tt.want {
t.Errorf("got %#v, want %#v", got.Element, tt.want.Element)
}
})
}
}

0 comments on commit 246eebf

Please sign in to comment.