예제 #1
0
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")))
}
예제 #2
0
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")))
}
예제 #3
0
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")))
}
예제 #4
0
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")))
}
예제 #5
0
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)")))
}
예제 #6
0
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)")))
}
예제 #7
0
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)
}
예제 #8
0
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)
}
예제 #9
0
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"))
}