Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,14 @@ func (c *Call) matches(args []interface{}) error {
// The last arg has a possibility of a variadic argument, so let it branch

// sample: Foo(a int, b int, c ...int)
if len(c.args) == len(args) {
if i < len(c.args) && i < len(args) {
if m.Matches(args[i]) {
// Got Foo(a, b, c) want Foo(matcherA, matcherB, gomock.Any())
// Got Foo(a, b, c) want Foo(matcherA, matcherB, someSliceMatcher)
// Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC)
// Got Foo(a, b) want Foo(matcherA, matcherB)
// Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD)
break
continue
}
}

Expand Down
10 changes: 5 additions & 5 deletions sample/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func TestVariadicFunction(t *testing.T) {
defer ctrl.Finish()

mockIndex := mock_user.NewMockIndex(ctrl)
mockIndex.EXPECT().Ellip("%d", 0, 1, 1, 2, 3).Do(func(format string, nums ...int) {
mockIndex.EXPECT().Ellip("%d", 5, 6, 7, 8).Do(func(format string, nums ...int) {
sum := 0
for _, value := range nums {
sum += value
}
if sum != 7 {
if sum != 26 {
t.Errorf("Expected 7, got %d", sum)
}
})
Expand All @@ -82,7 +82,7 @@ func TestVariadicFunction(t *testing.T) {
for _, value := range nums {
sum += value
}
if sum != 7 {
if sum != 10 {
t.Errorf("Expected 7, got %d", sum)
}
})
Expand Down Expand Up @@ -114,8 +114,8 @@ func TestVariadicFunction(t *testing.T) {
}
})

mockIndex.Ellip("%d", 0, 1, 1, 2, 3)
mockIndex.Ellip("%d", 0, 1, 1, 2, 3)
mockIndex.Ellip("%d", 1, 2, 3, 4) // Match second matcher.
mockIndex.Ellip("%d", 5, 6, 7, 8) // Match first matcher.
mockIndex.Ellip("%d", 0)
mockIndex.Ellip("%d")
mockIndex.Ellip("%d")
Expand Down