mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: add direct call tests to TestMakeFuncVariadic
TestMakeFuncVariadic only called the variadic function via Call and CallSlice, not via a direct function call. I thought these tests would fail under gccgo tip, but they don't. Still seems worth having though. LGTM=iant R=golang-codereviews, gobot, iant CC=golang-codereviews https://golang.org/cl/152060043
This commit is contained in:
parent
91e8554b8b
commit
14cd40d912
1 changed files with 22 additions and 1 deletions
|
|
@ -1543,7 +1543,17 @@ func TestMakeFuncVariadic(t *testing.T) {
|
|||
fv := MakeFunc(TypeOf(fn), func(in []Value) []Value { return in[1:2] })
|
||||
ValueOf(&fn).Elem().Set(fv)
|
||||
|
||||
r := fv.Call([]Value{ValueOf(1), ValueOf(2), ValueOf(3)})[0].Interface().([]int)
|
||||
r := fn(1, 2, 3)
|
||||
if r[0] != 2 || r[1] != 3 {
|
||||
t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
|
||||
}
|
||||
|
||||
r = fn(1, []int{2, 3}...)
|
||||
if r[0] != 2 || r[1] != 3 {
|
||||
t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
|
||||
}
|
||||
|
||||
r = fv.Call([]Value{ValueOf(1), ValueOf(2), ValueOf(3)})[0].Interface().([]int)
|
||||
if r[0] != 2 || r[1] != 3 {
|
||||
t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
|
||||
}
|
||||
|
|
@ -1552,6 +1562,17 @@ func TestMakeFuncVariadic(t *testing.T) {
|
|||
if r[0] != 2 || r[1] != 3 {
|
||||
t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
|
||||
}
|
||||
|
||||
f := fv.Interface().(func(int, ...int) []int)
|
||||
|
||||
r = f(1, 2, 3)
|
||||
if r[0] != 2 || r[1] != 3 {
|
||||
t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
|
||||
}
|
||||
r = f(1, []int{2, 3}...)
|
||||
if r[0] != 2 || r[1] != 3 {
|
||||
t.Errorf("Call returned [%v, %v]; want 2, 3", r[0], r[1])
|
||||
}
|
||||
}
|
||||
|
||||
type Point struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue