10 func TestCallbackArgCast(t *testing.T) {
11 intConv := callbackSyntheticForTests(reflect.ValueOf(int64(math.MaxInt64)), nil)
12 floatConv := callbackSyntheticForTests(reflect.ValueOf(float64(math.MaxFloat64)), nil)
13 errConv := callbackSyntheticForTests(reflect.Value{}, errors.New("test"))
16 f callbackArgConverter
19 {intConv, reflect.ValueOf(int8(-1))},
20 {intConv, reflect.ValueOf(int16(-1))},
21 {intConv, reflect.ValueOf(int32(-1))},
22 {intConv, reflect.ValueOf(uint8(math.MaxUint8))},
23 {intConv, reflect.ValueOf(uint16(math.MaxUint16))},
24 {intConv, reflect.ValueOf(uint32(math.MaxUint32))},
25 // Special case, int64->uint64 is only 1<<63 - 1, not 1<<64 - 1
26 {intConv, reflect.ValueOf(uint64(math.MaxInt64))},
27 {floatConv, reflect.ValueOf(float32(math.Inf(1)))},
30 for _, test := range tests {
31 conv := callbackArgCast{test.f, test.o.Type()}
32 val, err := conv.Run(nil)
34 t.Errorf("Couldn't convert to %s: %s", test.o.Type(), err)
35 } else if !reflect.DeepEqual(val.Interface(), test.o.Interface()) {
36 t.Errorf("Unexpected result from converting to %s: got %v, want %v", test.o.Type(), val.Interface(), test.o.Interface())
40 conv := callbackArgCast{errConv, reflect.TypeOf(int8(0))}
41 _, err := conv.Run(nil)
43 t.Errorf("Expected error during callbackArgCast, but got none")
47 func TestCallbackConverters(t *testing.T) {
52 // Unfortunately, we can't tell which converter was returned,
53 // but we can at least check which types can be converted.
71 {complex64(complex(0, 0)), true},
72 {complex128(complex(0, 0)), true},
74 {map[string]string{}, true},
77 {make(chan int), true},
80 for _, test := range tests {
81 _, err := callbackArg(reflect.TypeOf(test.v))
82 if test.err && err == nil {
83 t.Errorf("Expected an error when converting %s, got no error", reflect.TypeOf(test.v))
84 } else if !test.err && err != nil {
85 t.Errorf("Expected converter when converting %s, got error: %s", reflect.TypeOf(test.v), err)
89 for _, test := range tests {
90 _, err := callbackRet(reflect.TypeOf(test.v))
91 if test.err && err == nil {
92 t.Errorf("Expected an error when converting %s, got no error", reflect.TypeOf(test.v))
93 } else if !test.err && err != nil {
94 t.Errorf("Expected converter when converting %s, got error: %s", reflect.TypeOf(test.v), err)