示例#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 *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"))
}
示例#8
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)
}
示例#9
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)
}