func (t *SaveArgTest) DestinationIsLiteralNil() { const index = 0 f := func(a int, b int) {} err := oglemock.SaveArg(index, nil).SetSignature(reflect.TypeOf(f)) ExpectThat(err, Error(HasSubstr("not a pointer"))) }
func (t *SaveArgTest) DestinationIsNotAPointer() { const index = 0 f := func(a int, b int) {} err := oglemock.SaveArg(index, uint(17)).SetSignature(reflect.TypeOf(f)) ExpectThat(err, Error(HasSubstr("pointer"))) ExpectThat(err, Error(HasSubstr("uint"))) }
func (t *SaveArgTest) DestinationIsNilPointer() { const index = 1 var dst *int f := func(a int, b int) {} err := oglemock.SaveArg(index, dst).SetSignature(reflect.TypeOf(f)) ExpectThat(err, Error(HasSubstr("pointer"))) ExpectThat(err, Error(HasSubstr("non-nil"))) }
func (t *SaveArgTest) DestinationNotAssignableFromSource() { const index = 1 var dst int f := func(a int, b string) {} err := oglemock.SaveArg(index, &dst).SetSignature(reflect.TypeOf(f)) ExpectThat(err, Error(HasSubstr("int"))) ExpectThat(err, Error(HasSubstr("assignable"))) ExpectThat(err, Error(HasSubstr("string"))) }
func (t *SaveArgTest) ArgumentIndexOutOfRange() { const index = 2 var dst int f := func(a int, b int) {} err := oglemock.SaveArg(index, &dst).SetSignature(reflect.TypeOf(f)) ExpectThat(err, Error(HasSubstr("index 2"))) ExpectThat(err, Error(HasSubstr("Out of range"))) ExpectThat(err, Error(HasSubstr("func(int, int)"))) }
func (t *SaveArgTest) FunctionHasNoArguments() { const index = 0 var dst int f := func() (int, string) { return 0, "" } err := oglemock.SaveArg(index, &dst).SetSignature(reflect.TypeOf(f)) ExpectThat(err, Error(HasSubstr("index 0"))) ExpectThat(err, Error(HasSubstr("Out of range"))) ExpectThat(err, Error(HasSubstr("func() (int, string)"))) }
func (t *SaveArgTest) AssignableTypeMatch() { const index = 1 var dst io.Reader f := func(a int, b *os.File) {} action := oglemock.SaveArg(index, &dst) AssertEq(nil, action.SetSignature(reflect.TypeOf(f))) var a int = 17 var b *os.File = os.Stdout _ = action.Invoke([]interface{}{a, b}) ExpectEq(os.Stdout, dst) }
func (t *SaveArgTest) ExactTypeMatch() { const index = 1 var dst int f := func(a int, b int) {} action := oglemock.SaveArg(index, &dst) AssertEq(nil, action.SetSignature(reflect.TypeOf(f))) var a int = 17 var b int = 19 _ = action.Invoke([]interface{}{a, b}) ExpectEq(19, dst) }
func (t *DoAllTest) MultipleActions() { f := func(a int) string { return "" } var saved int a0 := oglemock.SaveArg(0, &saved) a1 := oglemock.Return("taco") action := oglemock.DoAll(a0, a1) AssertEq(nil, action.SetSignature(reflect.TypeOf(f))) rets := action.Invoke([]interface{}{17}) ExpectEq(17, saved) ExpectThat(rets, ElementsAre("taco")) }