diff options
author | Michael Hudson-Doyle <michael.hudson@linaro.org> | 2014-10-08 15:58:56 -0700 |
---|---|---|
committer | Michael Hudson-Doyle <michael.hudson@linaro.org> | 2014-10-08 15:58:56 -0700 |
commit | ff4dfbe28e0119e5759888401ee3d837082e1479 (patch) | |
tree | cc326e01f217724d058c6dec3906b0a22a5711ca /src/reflect | |
parent | 68bc155352275d8e292e8c8c8b3cff1c24492d08 (diff) | |
download | go-ff4dfbe28e0119e5759888401ee3d837082e1479.tar.gz |
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://codereview.appspot.com/152060043
Committer: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/all_test.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index f13b91b74..f0cd6a412 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -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 { |