-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tchssk/expr-container-test
Add tests for expr.Container(s)
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |