walk: handle functions...
This commit is contained in:
parent
ab7818e9ea
commit
a0bad4d6e9
@ -35,6 +35,11 @@ func Walk(x interface{}, fn func(string)) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case reflect.Func:
|
||||||
|
valFnResult := val.Call(nil)
|
||||||
|
for _, res := range valFnResult {
|
||||||
|
walkValue(res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,21 @@ func TestWalk(t *testing.T) {
|
|||||||
t.Errorf("got %v want %v", got, want)
|
t.Errorf("got %v want %v", got, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("with functions", func(t *testing.T) {
|
||||||
|
aFunction := func() (Profile, Profile) {
|
||||||
|
return Profile{21, "Berlin"}, Profile{28, "Beijing"}
|
||||||
|
}
|
||||||
|
|
||||||
|
var got []string
|
||||||
|
want := []string{"Berlin", "Beijing"}
|
||||||
|
Walk(aFunction, func(input string) {
|
||||||
|
got = append(got, input)
|
||||||
|
})
|
||||||
|
if !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("got %v want %v", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertContains(t testing.TB, haystack []string, needle string) {
|
func assertContains(t testing.TB, haystack []string, needle string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user