Skip to content

Commit

Permalink
Merge pull request #11 from tchssk/expr-person-test
Browse files Browse the repository at this point in the history
Add tests for expr.(Person|People)
  • Loading branch information
raphael committed Jan 31, 2022
2 parents 436459a + c3f312e commit 03d6e7f
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions expr/person_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package expr

import (
"fmt"
"testing"
)

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

func TestPersonFinalize(t *testing.T) {
t.Parallel()
person := Person{
Element: &Element{
Name: "foo",
},
}
tests := []struct {
pre func()
want string
}{
{want: ""},
{pre: func() { person.Tags = "foo" }, want: "foo"},
{pre: func() { person.Finalize() }, want: "Element,Person,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 := person.Tags; got != tt.want {
t.Errorf("got %s, want %s", got, tt.want)
}
})
}
}

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

0 comments on commit 03d6e7f

Please sign in to comment.