44 lines
728 B
Go
44 lines
728 B
Go
package walk
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestWalk(t *testing.T) {
|
|
cases := []struct {
|
|
Name string
|
|
Input interface{}
|
|
ExpectedCalls []string
|
|
}{
|
|
{
|
|
"struct with one string field",
|
|
struct {
|
|
Name string
|
|
}{"Chris"},
|
|
[]string{"Chris"},
|
|
},
|
|
{
|
|
"struct with two string fields",
|
|
struct {
|
|
Name string
|
|
City string
|
|
}{"Chris", "London"},
|
|
[]string{"Chris", "London"},
|
|
},
|
|
}
|
|
|
|
for _, test := range cases {
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
var got []string
|
|
Walk(test.Input, func(input string) {
|
|
got = append(got, input)
|
|
})
|
|
|
|
if !reflect.DeepEqual(got, test.ExpectedCalls) {
|
|
t.Errorf("got %v want %v", got, test.ExpectedCalls)
|
|
}
|
|
})
|
|
}
|
|
}
|