Esempio n. 1
0
func (t *DoAllTest) LastActionDoesntLikeSignature() {
	f := func(a int, b string) {}

	a0 := oglemock.Invoke(f)
	a1 := oglemock.Invoke(f)
	a2 := oglemock.Return(17)

	err := oglemock.DoAll(a0, a1, a2).SetSignature(reflect.TypeOf(f))
	ExpectThat(err, Error(HasSubstr("Action 2")))
	ExpectThat(err, Error(HasSubstr("1 vals; expected 0")))
}
Esempio n. 2
0
func (t *InvokeTest) FunctionHasOneWrongOutputType() {
	f := func() (int32, string) { return 0, "" }
	g := func() (int, string) { return 0, "" }

	err := oglemock.Invoke(f).SetSignature(reflect.TypeOf(g))
	ExpectThat(err, Error(HasSubstr("func() (int32, string)")))
	ExpectThat(err, Error(HasSubstr("func() (int, string)")))
}
Esempio n. 3
0
func (t *InvokeTest) FunctionHasOneWrongInputType() {
	f := func(a int, b int32, c string) {}
	g := func(a int, b int, c string) {}

	err := oglemock.Invoke(f).SetSignature(reflect.TypeOf(g))
	ExpectThat(err, Error(HasSubstr("func(int, int32, string)")))
	ExpectThat(err, Error(HasSubstr("func(int, int, string)")))
}
Esempio n. 4
0
func (t *MockTest) InvokeFunction() {
	var suppliedX, suppliedY int
	f := func(x, y int) color.Color {
		suppliedX = x
		suppliedY = y
		return color.Gray{17}
	}

	ExpectCall(t.image, "At")(Any(), Any()).
		WillOnce(oglemock.Invoke(f))

	ExpectThat(t.image.At(-1, 12), IdenticalTo(color.Gray{17}))
	ExpectEq(-1, suppliedX)
	ExpectEq(12, suppliedY)
}
Esempio n. 5
0
func (t *InvokeTest) ReturnsFunctionResult() {
	expectedReturn0 := int16(3)
	expectedReturn1 := "taco"

	f := func() (int16, string) {
		return expectedReturn0, expectedReturn1
	}

	a := oglemock.Invoke(f)

	// Set signature.
	AssertEq(nil, a.SetSignature(reflect.TypeOf(f)))

	// Call the action.
	res := a.Invoke([]interface{}{})

	ExpectThat(
		res,
		ElementsAre(
			IdenticalTo(expectedReturn0),
			IdenticalTo(expectedReturn1)))
}
Esempio n. 6
0
func (t *InvokeTest) CallsFunction() {
	var actualArg0, actualArg1 interface{}

	f := func(a uintptr, b int8) {
		actualArg0 = a
		actualArg1 = b
	}

	a := oglemock.Invoke(f)

	// Set signature.
	AssertEq(nil, a.SetSignature(reflect.TypeOf(f)))

	// Call the action.
	expectedArg0 := uintptr(17)
	expectedArg1 := int8(-7)

	a.Invoke([]interface{}{expectedArg0, expectedArg1})

	ExpectThat(actualArg0, IdenticalTo(expectedArg0))
	ExpectThat(actualArg1, IdenticalTo(expectedArg1))
}
Esempio n. 7
0
func (t *InvokeTest) ArgumentIsInt() {
	f := func() { oglemock.Invoke(17) }
	ExpectThat(f, Panics(MatchesRegexp("Invoke.*function.*int")))
}
Esempio n. 8
0
func (t *InvokeTest) ArgumentIsNil() {
	f := func() { oglemock.Invoke(nil) }
	ExpectThat(f, Panics(MatchesRegexp("Invoke.*function.*<nil>")))
}