From 42810d368a766a295f95a92dede9d52162cdd6c0 Mon Sep 17 00:00:00 2001 From: wangyufeng Date: Mon, 8 Aug 2022 15:58:16 +0800 Subject: [PATCH 1/3] support embedded generic interfaces --- mockgen/generic_go118.go | 30 +- mockgen/generic_notgo118.go | 7 +- mockgen/internal/tests/generics/external.go | 49 ++ mockgen/internal/tests/generics/generics.go | 5 + mockgen/internal/tests/generics/go.mod | 6 +- .../internal/tests/generics/other/other.go | 10 + .../tests/generics/source/assert_test.go | 12 + .../generics/source/mock_external_test.go | 569 ++++++++++++++++++ .../generics/source/mock_generics_test.go | 52 ++ mockgen/parse.go | 123 +++- 10 files changed, 833 insertions(+), 30 deletions(-) create mode 100644 mockgen/internal/tests/generics/source/assert_test.go diff --git a/mockgen/generic_go118.go b/mockgen/generic_go118.go index 917a15e..3b8ba6b 100644 --- a/mockgen/generic_go118.go +++ b/mockgen/generic_go118.go @@ -11,6 +11,7 @@ package main import ( + "fmt" "go/ast" "strings" @@ -24,7 +25,7 @@ func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { return ts.TypeParams.List } -func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { +func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { switch v := typ.(type) { case *ast.IndexExpr: m, err := p.parseType(pkg, v.X, tps) @@ -86,3 +87,30 @@ func getIdentTypeParams(decl interface{}) string { sb.WriteString("]") return sb.String() } + +func (p *fileParser) parseGenericMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + var indices []ast.Expr + var typ ast.Expr + switch v := field.Type.(type) { + case *ast.IndexExpr: + indices = []ast.Expr{v.Index} + typ = v.X + case *ast.IndexListExpr: + indices = v.Indices + typ = v.X + default: + return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) + } + + nf := &ast.Field{ + Doc: field.Comment, + Names: field.Names, + Type: typ, + Tag: field.Tag, + Comment: field.Comment, + } + + it.embeddedInstTypeParams = indices + + return p.parseMethod(nf, it, iface, pkg, tps) +} diff --git a/mockgen/generic_notgo118.go b/mockgen/generic_notgo118.go index b608438..b991b64 100644 --- a/mockgen/generic_notgo118.go +++ b/mockgen/generic_notgo118.go @@ -18,6 +18,7 @@ package main import ( + "fmt" "go/ast" "go.uber.org/mock/mockgen/model" @@ -27,10 +28,14 @@ func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { return nil } -func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { +func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { return nil, nil } func getIdentTypeParams(decl interface{}) string { return "" } + +func (p *fileParser) parseGenericMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) +} diff --git a/mockgen/internal/tests/generics/external.go b/mockgen/internal/tests/generics/external.go index 68b2d4b..5d3831f 100644 --- a/mockgen/internal/tests/generics/external.go +++ b/mockgen/internal/tests/generics/external.go @@ -1,6 +1,8 @@ package generics import ( + "context" + "go.uber.org/mock/mockgen/internal/tests/generics/other" "golang.org/x/exp/constraints" ) @@ -19,3 +21,50 @@ type ExternalConstraint[I constraints.Integer, F constraints.Float] interface { Nine(Iface[I]) Ten(*I) } + +type EmbeddingIface[T constraints.Integer, R constraints.Float] interface { + other.Twenty[T, StructType, R, other.Five] + TwentyTwo[StructType] + other.TwentyThree[TwentyTwo[R], TwentyTwo[T]] + TwentyFour[other.StructType] + Foo() error + ExternalConstraint[T, R] +} + +type TwentyOne[T any] interface { + TwentyOne() T +} + +type TwentyFour[T other.StructType] interface { + TwentyFour() T +} + +type Clonable[T any] interface { + Clone() T +} + +type Finder[T Clonable[T]] interface { + Find(ctx context.Context) ([]T, error) +} + +type UpdateNotifier[T any] interface { + NotifyC(ctx context.Context) <-chan []T + + Refresh(ctx context.Context) +} + +type EmbeddedW[W StructType] interface { + EmbeddedY[W] +} + +type EmbeddedX[X StructType] interface { + EmbeddedY[X] +} + +type EmbeddedY[Y StructType] interface { + EmbeddedZ[Y] +} + +type EmbeddedZ[Z any] interface { + EmbeddedZ(Z) +} diff --git a/mockgen/internal/tests/generics/generics.go b/mockgen/internal/tests/generics/generics.go index 647a6fc..9ea7dde 100644 --- a/mockgen/internal/tests/generics/generics.go +++ b/mockgen/internal/tests/generics/generics.go @@ -25,6 +25,7 @@ type Bar[T any, R any] interface { Seventeen() (*Foo[other.Three, other.Four], error) Eighteen() (Iface[*other.Five], error) Nineteen() AliasType + other.Twenty[any, any, any, *other.Four] } type Foo[T any, R any] struct{} @@ -38,3 +39,7 @@ type StructType struct{} type StructType2 struct{} type AliasType Baz[other.Three] + +type TwentyTwo[T any] interface { + TwentyTwo() T +} diff --git a/mockgen/internal/tests/generics/go.mod b/mockgen/internal/tests/generics/go.mod index 7eb82e1..f29c15e 100644 --- a/mockgen/internal/tests/generics/go.mod +++ b/mockgen/internal/tests/generics/go.mod @@ -1,10 +1,10 @@ -module github.com/golang/mock/mockgen/internal/tests/generics +module go.uber.org/mock/mockgen/internal/tests/generics go 1.18 require ( - github.com/golang/mock v1.6.0 + go.uber.org/mock v1.6.0 golang.org/x/exp v0.0.0-20220428152302-39d4317da171 ) -replace github.com/golang/mock => ../../../.. +replace go.uber.org/mock => ../../../.. diff --git a/mockgen/internal/tests/generics/other/other.go b/mockgen/internal/tests/generics/other/other.go index 9265422..6129131 100644 --- a/mockgen/internal/tests/generics/other/other.go +++ b/mockgen/internal/tests/generics/other/other.go @@ -9,3 +9,13 @@ type Three struct{} type Four struct{} type Five interface{} + +type Twenty[R, S, T any, Z any] interface { + Twenty(S, R) (T, Z) +} + +type TwentyThree[U, V any] interface { + TwentyThree(U, V) StructType +} + +type StructType struct{} diff --git a/mockgen/internal/tests/generics/source/assert_test.go b/mockgen/internal/tests/generics/source/assert_test.go new file mode 100644 index 0000000..1168a41 --- /dev/null +++ b/mockgen/internal/tests/generics/source/assert_test.go @@ -0,0 +1,12 @@ +package source + +import ( + "testing" + + "github.com/golang/mock/mockgen/internal/tests/generics" +) + +func TestAssert(t *testing.T) { + var x MockEmbeddingIface[int, float64] + var _ generics.EmbeddingIface[int, float64] = &x +} diff --git a/mockgen/internal/tests/generics/source/mock_external_test.go b/mockgen/internal/tests/generics/source/mock_external_test.go index 32a876b..fc0fe8b 100644 --- a/mockgen/internal/tests/generics/source/mock_external_test.go +++ b/mockgen/internal/tests/generics/source/mock_external_test.go @@ -5,6 +5,7 @@ package source import ( + context "context" reflect "reflect" gomock "go.uber.org/mock/gomock" @@ -171,3 +172,571 @@ func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 interface{}) *gomoc mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) } + +// MockEmbeddingIface is a mock of EmbeddingIface interface. +type MockEmbeddingIface[T constraints.Integer, R constraints.Float] struct { + ctrl *gomock.Controller + recorder *MockEmbeddingIfaceMockRecorder[T, R] +} + +// MockEmbeddingIfaceMockRecorder is the mock recorder for MockEmbeddingIface. +type MockEmbeddingIfaceMockRecorder[T constraints.Integer, R constraints.Float] struct { + mock *MockEmbeddingIface[T, R] +} + +// NewMockEmbeddingIface creates a new mock instance. +func NewMockEmbeddingIface[T constraints.Integer, R constraints.Float](ctrl *gomock.Controller) *MockEmbeddingIface[T, R] { + mock := &MockEmbeddingIface[T, R]{ctrl: ctrl} + mock.recorder = &MockEmbeddingIfaceMockRecorder[T, R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddingIface[T, R]) EXPECT() *MockEmbeddingIfaceMockRecorder[T, R] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockEmbeddingIface[T, R]) Eight(arg0 R) other.Two[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[T, R]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eight(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eight), arg0) +} + +// Five mocks base method. +func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[R]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) +} + +// Foo mocks base method. +func (m *MockEmbeddingIface[T, R]) Foo() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Foo") + ret0, _ := ret[0].(error) + return ret0 +} + +// Foo indicates an expected call of Foo. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Foo() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Foo", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Foo)) +} + +// Four mocks base method. +func (m *MockEmbeddingIface[T, R]) Four(arg0 T) generics.Foo[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[T, R]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Four(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Four), arg0) +} + +// Nine mocks base method. +func (m *MockEmbeddingIface[T, R]) Nine(arg0 generics.Iface[T]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Nine(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockEmbeddingIface[T, R]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).One), arg0) +} + +// Seven mocks base method. +func (m *MockEmbeddingIface[T, R]) Seven(arg0 T) other.One[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[T]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Seven(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockEmbeddingIface[T, R]) Six(arg0 T) *generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[R]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Six(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockEmbeddingIface[T, R]) Ten(arg0 *T) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Ten(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Ten), arg0) +} + +// Three mocks base method. +func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(R) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) +} + +// Twenty mocks base method. +func (m *MockEmbeddingIface[T, R]) Twenty(arg0 generics.StructType, arg1 T) (R, other.Five) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twenty", arg0, arg1) + ret0, _ := ret[0].(R) + ret1, _ := ret[1].(other.Five) + return ret0, ret1 +} + +// Twenty indicates an expected call of Twenty. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twenty(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twenty", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twenty), arg0, arg1) +} + +// TwentyFour mocks base method. +func (m *MockEmbeddingIface[T, R]) TwentyFour() other.StructType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TwentyFour") + ret0, _ := ret[0].(other.StructType) + return ret0 +} + +// TwentyFour indicates an expected call of TwentyFour. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) TwentyFour() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyFour", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).TwentyFour)) +} + +// TwentyThree mocks base method. +func (m *MockEmbeddingIface[T, R]) TwentyThree(arg0 generics.TwentyTwo[R], arg1 generics.TwentyTwo[T]) other.StructType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TwentyThree", arg0, arg1) + ret0, _ := ret[0].(other.StructType) + return ret0 +} + +// TwentyThree indicates an expected call of TwentyThree. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) TwentyThree(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyThree", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).TwentyThree), arg0, arg1) +} + +// TwentyTwo mocks base method. +func (m *MockEmbeddingIface[T, R]) TwentyTwo() generics.StructType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TwentyTwo") + ret0, _ := ret[0].(generics.StructType) + return ret0 +} + +// TwentyTwo indicates an expected call of TwentyTwo. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) TwentyTwo() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyTwo", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).TwentyTwo)) +} + +// Two mocks base method. +func (m *MockEmbeddingIface[T, R]) Two(arg0 T) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Two(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Two), arg0) +} + +// MockTwentyOne is a mock of TwentyOne interface. +type MockTwentyOne[T any] struct { + ctrl *gomock.Controller + recorder *MockTwentyOneMockRecorder[T] +} + +// MockTwentyOneMockRecorder is the mock recorder for MockTwentyOne. +type MockTwentyOneMockRecorder[T any] struct { + mock *MockTwentyOne[T] +} + +// NewMockTwentyOne creates a new mock instance. +func NewMockTwentyOne[T any](ctrl *gomock.Controller) *MockTwentyOne[T] { + mock := &MockTwentyOne[T]{ctrl: ctrl} + mock.recorder = &MockTwentyOneMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockTwentyOne[T]) EXPECT() *MockTwentyOneMockRecorder[T] { + return m.recorder +} + +// TwentyOne mocks base method. +func (m *MockTwentyOne[T]) TwentyOne() T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TwentyOne") + ret0, _ := ret[0].(T) + return ret0 +} + +// TwentyOne indicates an expected call of TwentyOne. +func (mr *MockTwentyOneMockRecorder[T]) TwentyOne() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyOne", reflect.TypeOf((*MockTwentyOne[T])(nil).TwentyOne)) +} + +// MockTwentyFour is a mock of TwentyFour interface. +type MockTwentyFour[T other.StructType] struct { + ctrl *gomock.Controller + recorder *MockTwentyFourMockRecorder[T] +} + +// MockTwentyFourMockRecorder is the mock recorder for MockTwentyFour. +type MockTwentyFourMockRecorder[T other.StructType] struct { + mock *MockTwentyFour[T] +} + +// NewMockTwentyFour creates a new mock instance. +func NewMockTwentyFour[T other.StructType](ctrl *gomock.Controller) *MockTwentyFour[T] { + mock := &MockTwentyFour[T]{ctrl: ctrl} + mock.recorder = &MockTwentyFourMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockTwentyFour[T]) EXPECT() *MockTwentyFourMockRecorder[T] { + return m.recorder +} + +// TwentyFour mocks base method. +func (m *MockTwentyFour[T]) TwentyFour() T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TwentyFour") + ret0, _ := ret[0].(T) + return ret0 +} + +// TwentyFour indicates an expected call of TwentyFour. +func (mr *MockTwentyFourMockRecorder[T]) TwentyFour() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyFour", reflect.TypeOf((*MockTwentyFour[T])(nil).TwentyFour)) +} + +// MockClonable is a mock of Clonable interface. +type MockClonable[T any] struct { + ctrl *gomock.Controller + recorder *MockClonableMockRecorder[T] +} + +// MockClonableMockRecorder is the mock recorder for MockClonable. +type MockClonableMockRecorder[T any] struct { + mock *MockClonable[T] +} + +// NewMockClonable creates a new mock instance. +func NewMockClonable[T any](ctrl *gomock.Controller) *MockClonable[T] { + mock := &MockClonable[T]{ctrl: ctrl} + mock.recorder = &MockClonableMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClonable[T]) EXPECT() *MockClonableMockRecorder[T] { + return m.recorder +} + +// Clone mocks base method. +func (m *MockClonable[T]) Clone() T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Clone") + ret0, _ := ret[0].(T) + return ret0 +} + +// Clone indicates an expected call of Clone. +func (mr *MockClonableMockRecorder[T]) Clone() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clone", reflect.TypeOf((*MockClonable[T])(nil).Clone)) +} + +// MockFinder is a mock of Finder interface. +type MockFinder[T generics.Clonable[T]] struct { + ctrl *gomock.Controller + recorder *MockFinderMockRecorder[T] +} + +// MockFinderMockRecorder is the mock recorder for MockFinder. +type MockFinderMockRecorder[T generics.Clonable[T]] struct { + mock *MockFinder[T] +} + +// NewMockFinder creates a new mock instance. +func NewMockFinder[T generics.Clonable[T]](ctrl *gomock.Controller) *MockFinder[T] { + mock := &MockFinder[T]{ctrl: ctrl} + mock.recorder = &MockFinderMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFinder[T]) EXPECT() *MockFinderMockRecorder[T] { + return m.recorder +} + +// Find mocks base method. +func (m *MockFinder[T]) Find(ctx context.Context) ([]T, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Find", ctx) + ret0, _ := ret[0].([]T) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Find indicates an expected call of Find. +func (mr *MockFinderMockRecorder[T]) Find(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Find", reflect.TypeOf((*MockFinder[T])(nil).Find), ctx) +} + +// MockUpdateNotifier is a mock of UpdateNotifier interface. +type MockUpdateNotifier[T any] struct { + ctrl *gomock.Controller + recorder *MockUpdateNotifierMockRecorder[T] +} + +// MockUpdateNotifierMockRecorder is the mock recorder for MockUpdateNotifier. +type MockUpdateNotifierMockRecorder[T any] struct { + mock *MockUpdateNotifier[T] +} + +// NewMockUpdateNotifier creates a new mock instance. +func NewMockUpdateNotifier[T any](ctrl *gomock.Controller) *MockUpdateNotifier[T] { + mock := &MockUpdateNotifier[T]{ctrl: ctrl} + mock.recorder = &MockUpdateNotifierMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockUpdateNotifier[T]) EXPECT() *MockUpdateNotifierMockRecorder[T] { + return m.recorder +} + +// NotifyC mocks base method. +func (m *MockUpdateNotifier[T]) NotifyC(ctx context.Context) <-chan []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NotifyC", ctx) + ret0, _ := ret[0].(<-chan []T) + return ret0 +} + +// NotifyC indicates an expected call of NotifyC. +func (mr *MockUpdateNotifierMockRecorder[T]) NotifyC(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NotifyC", reflect.TypeOf((*MockUpdateNotifier[T])(nil).NotifyC), ctx) +} + +// Refresh mocks base method. +func (m *MockUpdateNotifier[T]) Refresh(ctx context.Context) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Refresh", ctx) +} + +// Refresh indicates an expected call of Refresh. +func (mr *MockUpdateNotifierMockRecorder[T]) Refresh(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Refresh", reflect.TypeOf((*MockUpdateNotifier[T])(nil).Refresh), ctx) +} + +// MockEmbeddedW is a mock of EmbeddedW interface. +type MockEmbeddedW[W generics.StructType] struct { + ctrl *gomock.Controller + recorder *MockEmbeddedWMockRecorder[W] +} + +// MockEmbeddedWMockRecorder is the mock recorder for MockEmbeddedW. +type MockEmbeddedWMockRecorder[W generics.StructType] struct { + mock *MockEmbeddedW[W] +} + +// NewMockEmbeddedW creates a new mock instance. +func NewMockEmbeddedW[W generics.StructType](ctrl *gomock.Controller) *MockEmbeddedW[W] { + mock := &MockEmbeddedW[W]{ctrl: ctrl} + mock.recorder = &MockEmbeddedWMockRecorder[W]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddedW[W]) EXPECT() *MockEmbeddedWMockRecorder[W] { + return m.recorder +} + +// EmbeddedZ mocks base method. +func (m *MockEmbeddedW[W]) EmbeddedZ(arg0 W) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EmbeddedZ", arg0) +} + +// EmbeddedZ indicates an expected call of EmbeddedZ. +func (mr *MockEmbeddedWMockRecorder[W]) EmbeddedZ(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedZ", reflect.TypeOf((*MockEmbeddedW[W])(nil).EmbeddedZ), arg0) +} + +// MockEmbeddedX is a mock of EmbeddedX interface. +type MockEmbeddedX[X generics.StructType] struct { + ctrl *gomock.Controller + recorder *MockEmbeddedXMockRecorder[X] +} + +// MockEmbeddedXMockRecorder is the mock recorder for MockEmbeddedX. +type MockEmbeddedXMockRecorder[X generics.StructType] struct { + mock *MockEmbeddedX[X] +} + +// NewMockEmbeddedX creates a new mock instance. +func NewMockEmbeddedX[X generics.StructType](ctrl *gomock.Controller) *MockEmbeddedX[X] { + mock := &MockEmbeddedX[X]{ctrl: ctrl} + mock.recorder = &MockEmbeddedXMockRecorder[X]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddedX[X]) EXPECT() *MockEmbeddedXMockRecorder[X] { + return m.recorder +} + +// EmbeddedZ mocks base method. +func (m *MockEmbeddedX[X]) EmbeddedZ(arg0 X) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EmbeddedZ", arg0) +} + +// EmbeddedZ indicates an expected call of EmbeddedZ. +func (mr *MockEmbeddedXMockRecorder[X]) EmbeddedZ(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedZ", reflect.TypeOf((*MockEmbeddedX[X])(nil).EmbeddedZ), arg0) +} + +// MockEmbeddedY is a mock of EmbeddedY interface. +type MockEmbeddedY[Y generics.StructType] struct { + ctrl *gomock.Controller + recorder *MockEmbeddedYMockRecorder[Y] +} + +// MockEmbeddedYMockRecorder is the mock recorder for MockEmbeddedY. +type MockEmbeddedYMockRecorder[Y generics.StructType] struct { + mock *MockEmbeddedY[Y] +} + +// NewMockEmbeddedY creates a new mock instance. +func NewMockEmbeddedY[Y generics.StructType](ctrl *gomock.Controller) *MockEmbeddedY[Y] { + mock := &MockEmbeddedY[Y]{ctrl: ctrl} + mock.recorder = &MockEmbeddedYMockRecorder[Y]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddedY[Y]) EXPECT() *MockEmbeddedYMockRecorder[Y] { + return m.recorder +} + +// EmbeddedZ mocks base method. +func (m *MockEmbeddedY[Y]) EmbeddedZ(arg0 Y) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EmbeddedZ", arg0) +} + +// EmbeddedZ indicates an expected call of EmbeddedZ. +func (mr *MockEmbeddedYMockRecorder[Y]) EmbeddedZ(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedZ", reflect.TypeOf((*MockEmbeddedY[Y])(nil).EmbeddedZ), arg0) +} + +// MockEmbeddedZ is a mock of EmbeddedZ interface. +type MockEmbeddedZ[Z any] struct { + ctrl *gomock.Controller + recorder *MockEmbeddedZMockRecorder[Z] +} + +// MockEmbeddedZMockRecorder is the mock recorder for MockEmbeddedZ. +type MockEmbeddedZMockRecorder[Z any] struct { + mock *MockEmbeddedZ[Z] +} + +// NewMockEmbeddedZ creates a new mock instance. +func NewMockEmbeddedZ[Z any](ctrl *gomock.Controller) *MockEmbeddedZ[Z] { + mock := &MockEmbeddedZ[Z]{ctrl: ctrl} + mock.recorder = &MockEmbeddedZMockRecorder[Z]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddedZ[Z]) EXPECT() *MockEmbeddedZMockRecorder[Z] { + return m.recorder +} + +// EmbeddedZ mocks base method. +func (m *MockEmbeddedZ[Z]) EmbeddedZ(arg0 Z) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EmbeddedZ", arg0) +} + +// EmbeddedZ indicates an expected call of EmbeddedZ. +func (mr *MockEmbeddedZMockRecorder[Z]) EmbeddedZ(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedZ", reflect.TypeOf((*MockEmbeddedZ[Z])(nil).EmbeddedZ), arg0) +} diff --git a/mockgen/internal/tests/generics/source/mock_generics_test.go b/mockgen/internal/tests/generics/source/mock_generics_test.go index ad34340..e577026 100644 --- a/mockgen/internal/tests/generics/source/mock_generics_test.go +++ b/mockgen/internal/tests/generics/source/mock_generics_test.go @@ -291,6 +291,21 @@ func (mr *MockBarMockRecorder[T, R]) Twelve() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockBar[T, R])(nil).Twelve)) } +// Twenty mocks base method. +func (m *MockBar[T, R]) Twenty(arg0, arg1 any) (any, *other.Four) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twenty", arg0, arg1) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(*other.Four) + return ret0, ret1 +} + +// Twenty indicates an expected call of Twenty. +func (mr *MockBarMockRecorder[T, R]) Twenty(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twenty", reflect.TypeOf((*MockBar[T, R])(nil).Twenty), arg0, arg1) +} + // Two mocks base method. func (m *MockBar[T, R]) Two(arg0 T) string { m.ctrl.T.Helper() @@ -327,3 +342,40 @@ func NewMockIface[T any](ctrl *gomock.Controller) *MockIface[T] { func (m *MockIface[T]) EXPECT() *MockIfaceMockRecorder[T] { return m.recorder } + +// MockTwentyTwo is a mock of TwentyTwo interface. +type MockTwentyTwo[T any] struct { + ctrl *gomock.Controller + recorder *MockTwentyTwoMockRecorder[T] +} + +// MockTwentyTwoMockRecorder is the mock recorder for MockTwentyTwo. +type MockTwentyTwoMockRecorder[T any] struct { + mock *MockTwentyTwo[T] +} + +// NewMockTwentyTwo creates a new mock instance. +func NewMockTwentyTwo[T any](ctrl *gomock.Controller) *MockTwentyTwo[T] { + mock := &MockTwentyTwo[T]{ctrl: ctrl} + mock.recorder = &MockTwentyTwoMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockTwentyTwo[T]) EXPECT() *MockTwentyTwoMockRecorder[T] { + return m.recorder +} + +// TwentyTwo mocks base method. +func (m *MockTwentyTwo[T]) TwentyTwo() T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TwentyTwo") + ret0, _ := ret[0].(T) + return ret0 +} + +// TwentyTwo indicates an expected call of TwentyTwo. +func (mr *MockTwentyTwoMockRecorder[T]) TwentyTwo() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyTwo", reflect.TypeOf((*MockTwentyTwo[T])(nil).TwentyTwo)) +} diff --git a/mockgen/parse.go b/mockgen/parse.go index aab9066..a397922 100644 --- a/mockgen/parse.go +++ b/mockgen/parse.go @@ -274,20 +274,77 @@ func (p *fileParser) parsePackage(path string) (*fileParser, error) { return newP, nil } +func (p *fileParser) constructInstParams(pkg string, params []*ast.Field, instParams []model.Type, embeddedInstParams []ast.Expr, tps map[string]model.Type) ([]model.Type, error) { + pm := make(map[string]int) + var i int + for _, v := range params { + for _, n := range v.Names { + pm[n.Name] = i + instParams = append(instParams, model.PredeclaredType(n.Name)) + i++ + } + } + + var runtimeInstParams []model.Type + for _, instParam := range embeddedInstParams { + switch t := instParam.(type) { + case *ast.Ident: + if idx, ok := pm[t.Name]; ok { + runtimeInstParams = append(runtimeInstParams, instParams[idx]) + continue + } + } + modelType, err := p.parseType(pkg, instParam, tps) + if err != nil { + return nil, err + } + runtimeInstParams = append(runtimeInstParams, modelType) + } + + return runtimeInstParams, nil +} + +func (p *fileParser) constructTps(it *namedInterface) (tps map[string]model.Type) { + tps = make(map[string]model.Type) + n := 0 + for _, tp := range it.typeParams { + for _, tm := range tp.Names { + tps[tm.Name] = nil + if len(it.instTypes) != 0 { + tps[tm.Name] = it.instTypes[n] + n++ + } + } + } + return tps +} + +// parseInterface loads interface specified by pkg and name, parses it and returns +// a new model with the parsed. func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*model.Interface, error) { iface := &model.Interface{Name: name} - tps := make(map[string]bool) - + tps := p.constructTps(it) tp, err := p.parseFieldList(pkg, it.typeParams, tps) if err != nil { return nil, fmt.Errorf("unable to parse interface type parameters: %v", name) } + iface.TypeParams = tp - for _, v := range tp { - tps[v.Name] = true + for _, field := range it.it.Methods.List { + var methods []*model.Method + if methods, err = p.parseMethod(field, it, iface, pkg, tps); err != nil { + return nil, err + } + for _, m := range methods { + iface.AddMethod(m) + } } + return iface, nil +} - for _, field := range it.it.Methods.List { +func (p *fileParser) parseMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + // {} for git diff + { switch v := field.Type.(type) { case *ast.FuncType: if nn := len(field.Names); nn != 1 { @@ -301,7 +358,7 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode if err != nil { return nil, err } - iface.AddMethod(m) + return []*model.Method{m}, nil case *ast.Ident: // Embedded interface in this package. embeddedIfaceType := p.auxInterfaces.Get(pkg, v.String()) @@ -312,10 +369,15 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode var embeddedIface *model.Interface if embeddedIfaceType != nil { var err error + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = p.parseInterface(v.String(), pkg, embeddedIfaceType) if err != nil { return nil, err } + } else { // This is built-in error interface. if v.String() == model.ErrorInterface.Name { @@ -330,16 +392,17 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode return nil, p.errorf(v.Pos(), "unknown embedded interface %s.%s", pkg, v.String()) } + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = ip.parseInterface(v.String(), pkg, embeddedIfaceType) if err != nil { return nil, err } } } - // Copy the methods. - for _, m := range embeddedIface.Methods { - iface.AddMethod(m) - } + return embeddedIface.Methods, nil case *ast.SelectorExpr: // Embedded interface in another package. filePkg, sel := v.X.(*ast.Ident).String(), v.Sel.String() @@ -352,6 +415,10 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode var err error embeddedIfaceType := p.auxInterfaces.Get(filePkg, sel) if embeddedIfaceType != nil { + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = p.parseInterface(sel, filePkg, embeddedIfaceType) if err != nil { return nil, err @@ -373,24 +440,25 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode if embeddedIfaceType = parser.importedInterfaces.Get(path, sel); embeddedIfaceType == nil { return nil, p.errorf(v.Pos(), "unknown embedded interface %s.%s", path, sel) } + + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = parser.parseInterface(sel, path, embeddedIfaceType) if err != nil { return nil, err } } - // Copy the methods. // TODO: apply shadowing rules. - for _, m := range embeddedIface.Methods { - iface.AddMethod(m) - } + return embeddedIface.Methods, nil default: - return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) + return p.parseGenericMethod(field, it, iface, pkg, tps) } } - return iface, nil } -func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]bool) (inParam []*model.Parameter, variadic *model.Parameter, outParam []*model.Parameter, err error) { +func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]model.Type) (inParam []*model.Parameter, variadic *model.Parameter, outParam []*model.Parameter, err error) { if f.Params != nil { regParams := f.Params.List if isVariadic(f) { @@ -417,7 +485,7 @@ func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]bool) return } -func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[string]bool) ([]*model.Parameter, error) { +func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[string]model.Type) ([]*model.Parameter, error) { nf := 0 for _, f := range fields { nn := len(f.Names) @@ -451,7 +519,7 @@ func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[str return ps, nil } -func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { +func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { switch v := typ.(type) { case *ast.ArrayType: ln := -1 @@ -493,7 +561,8 @@ func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (m } return &model.FuncType{In: in, Out: out, Variadic: variadic}, nil case *ast.Ident: - if v.IsExported() && !tps[v.Name] { + it, ok := tps[v.Name] + if v.IsExported() && !ok { // `pkg` may be an aliased imported pkg // if so, patch the import w/ the fully qualified import maybeImportedPkg, ok := p.imports[pkg] @@ -503,7 +572,9 @@ func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (m // assume type in this package return &model.NamedType{Package: pkg, Type: v.Name}, nil } - + if ok && it != nil { + return it, nil + } // assume predeclared type return model.PredeclaredType(v.Name), nil case *ast.InterfaceType: @@ -657,9 +728,11 @@ func importsOfFile(file *ast.File) (normalImports map[string]importedPackage, do } type namedInterface struct { - name *ast.Ident - it *ast.InterfaceType - typeParams []*ast.Field + name *ast.Ident + it *ast.InterfaceType + typeParams []*ast.Field + embeddedInstTypeParams []ast.Expr + instTypes []model.Type } // Create an iterator over all interfaces in file. @@ -681,7 +754,7 @@ func iterInterfaces(file *ast.File) <-chan *namedInterface { continue } - ch <- &namedInterface{ts.Name, it, getTypeSpecTypeParams(ts)} + ch <- &namedInterface{name: ts.Name, it: it, typeParams: getTypeSpecTypeParams(ts)} } } close(ch) From 3aa6442f3fceb8aaf74f93ca4f6e1985a99d125e Mon Sep 17 00:00:00 2001 From: wangyufeng Date: Sun, 9 Jul 2023 09:22:25 +0800 Subject: [PATCH 2/3] optimize test case --- mockgen/internal/tests/generics/external.go | 53 +- mockgen/internal/tests/generics/generics.go | 22 +- mockgen/internal/tests/generics/go.sum | 24 - .../internal/tests/generics/other/other.go | 13 +- .../tests/generics/source/assert_test.go | 2 +- .../generics/source/mock_external_test.go | 557 +++++++----------- .../generics/source/mock_generics_test.go | 163 +++-- 7 files changed, 374 insertions(+), 460 deletions(-) diff --git a/mockgen/internal/tests/generics/external.go b/mockgen/internal/tests/generics/external.go index 5d3831f..87c8c9a 100644 --- a/mockgen/internal/tests/generics/external.go +++ b/mockgen/internal/tests/generics/external.go @@ -2,6 +2,7 @@ package generics import ( "context" + "io" "go.uber.org/mock/mockgen/internal/tests/generics/other" "golang.org/x/exp/constraints" @@ -9,7 +10,7 @@ import ( //go:generate mockgen --source=external.go --destination=source/mock_external_test.go --package source -type ExternalConstraint[I constraints.Integer, F constraints.Float] interface { +type ExternalConstraint[I constraints.Integer, F any] interface { One(string) string Two(I) string Three(I) F @@ -20,51 +21,23 @@ type ExternalConstraint[I constraints.Integer, F constraints.Float] interface { Eight(F) other.Two[I, F] Nine(Iface[I]) Ten(*I) + Eleven() map[string]I + Twelve(ctx context.Context) <-chan []I + Thirteen(...I) *F } type EmbeddingIface[T constraints.Integer, R constraints.Float] interface { - other.Twenty[T, StructType, R, other.Five] - TwentyTwo[StructType] - other.TwentyThree[TwentyTwo[R], TwentyTwo[T]] - TwentyFour[other.StructType] - Foo() error + io.Reader + Generater[R] + Earth[Generater[T]] + other.Either[R, StructType, other.Five, Generater[T]] ExternalConstraint[T, R] } -type TwentyOne[T any] interface { - TwentyOne() T +type Generater[T any] interface { + Generate() T } -type TwentyFour[T other.StructType] interface { - TwentyFour() T -} - -type Clonable[T any] interface { - Clone() T -} - -type Finder[T Clonable[T]] interface { - Find(ctx context.Context) ([]T, error) -} - -type UpdateNotifier[T any] interface { - NotifyC(ctx context.Context) <-chan []T - - Refresh(ctx context.Context) -} - -type EmbeddedW[W StructType] interface { - EmbeddedY[W] -} - -type EmbeddedX[X StructType] interface { - EmbeddedY[X] -} - -type EmbeddedY[Y StructType] interface { - EmbeddedZ[Y] -} - -type EmbeddedZ[Z any] interface { - EmbeddedZ(Z) +type Group[T Generater[T]] interface { + Join(ctx context.Context) ([]T, error) } diff --git a/mockgen/internal/tests/generics/generics.go b/mockgen/internal/tests/generics/generics.go index 9ea7dde..8a9778e 100644 --- a/mockgen/internal/tests/generics/generics.go +++ b/mockgen/internal/tests/generics/generics.go @@ -1,6 +1,9 @@ package generics -import "go.uber.org/mock/mockgen/internal/tests/generics/other" +import ( + "go.uber.org/mock/mockgen/internal/tests/generics/other" + "golang.org/x/exp/constraints" +) //go:generate mockgen --source=generics.go --destination=source/mock_generics_test.go --package source ////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2 @@ -25,7 +28,6 @@ type Bar[T any, R any] interface { Seventeen() (*Foo[other.Three, other.Four], error) Eighteen() (Iface[*other.Five], error) Nineteen() AliasType - other.Twenty[any, any, any, *other.Four] } type Foo[T any, R any] struct{} @@ -40,6 +42,18 @@ type StructType2 struct{} type AliasType Baz[other.Three] -type TwentyTwo[T any] interface { - TwentyTwo() T +type Universe[T constraints.Signed] interface { + MilkyWay[T] +} + +type MilkyWay[R constraints.Integer] interface { + SolarSystem[R] +} + +type SolarSystem[T constraints.Ordered] interface { + Earth[T] +} + +type Earth[R any] interface { + Water(R) []R } diff --git a/mockgen/internal/tests/generics/go.sum b/mockgen/internal/tests/generics/go.sum index c6f4464..698ce9b 100644 --- a/mockgen/internal/tests/generics/go.sum +++ b/mockgen/internal/tests/generics/go.sum @@ -1,26 +1,2 @@ -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4= golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/mockgen/internal/tests/generics/other/other.go b/mockgen/internal/tests/generics/other/other.go index 6129131..6de7fe1 100644 --- a/mockgen/internal/tests/generics/other/other.go +++ b/mockgen/internal/tests/generics/other/other.go @@ -10,12 +10,9 @@ type Four struct{} type Five interface{} -type Twenty[R, S, T any, Z any] interface { - Twenty(S, R) (T, Z) +type Either[T, R, K, V any] interface { + First() T + Second() R + Third() K + Fourth() V } - -type TwentyThree[U, V any] interface { - TwentyThree(U, V) StructType -} - -type StructType struct{} diff --git a/mockgen/internal/tests/generics/source/assert_test.go b/mockgen/internal/tests/generics/source/assert_test.go index 1168a41..ae825e7 100644 --- a/mockgen/internal/tests/generics/source/assert_test.go +++ b/mockgen/internal/tests/generics/source/assert_test.go @@ -3,7 +3,7 @@ package source import ( "testing" - "github.com/golang/mock/mockgen/internal/tests/generics" + "go.uber.org/mock/mockgen/internal/tests/generics" ) func TestAssert(t *testing.T) { diff --git a/mockgen/internal/tests/generics/source/mock_external_test.go b/mockgen/internal/tests/generics/source/mock_external_test.go index fc0fe8b..271698d 100644 --- a/mockgen/internal/tests/generics/source/mock_external_test.go +++ b/mockgen/internal/tests/generics/source/mock_external_test.go @@ -15,18 +15,18 @@ import ( ) // MockExternalConstraint is a mock of ExternalConstraint interface. -type MockExternalConstraint[I constraints.Integer, F constraints.Float] struct { +type MockExternalConstraint[I constraints.Integer, F any] struct { ctrl *gomock.Controller recorder *MockExternalConstraintMockRecorder[I, F] } // MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. -type MockExternalConstraintMockRecorder[I constraints.Integer, F constraints.Float] struct { +type MockExternalConstraintMockRecorder[I constraints.Integer, F any] struct { mock *MockExternalConstraint[I, F] } // NewMockExternalConstraint creates a new mock instance. -func NewMockExternalConstraint[I constraints.Integer, F constraints.Float](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { +func NewMockExternalConstraint[I constraints.Integer, F any](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { mock := &MockExternalConstraint[I, F]{ctrl: ctrl} mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} return mock @@ -51,6 +51,20 @@ func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) } +// Eleven mocks base method. +func (m *MockExternalConstraint[I, F]) Eleven() map[string]I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]I) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eleven)) +} + // Five mocks base method. func (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] { m.ctrl.T.Helper() @@ -145,6 +159,24 @@ func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) } +// Thirteen mocks base method. +func (m *MockExternalConstraint[I, F]) Thirteen(arg0 ...I) *F { + m.ctrl.T.Helper() + varargs := []interface{}{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*F) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockExternalConstraintMockRecorder[I, F]) Thirteen(arg0 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Thirteen), arg0...) +} + // Three mocks base method. func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { m.ctrl.T.Helper() @@ -159,6 +191,20 @@ func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) } +// Twelve mocks base method. +func (m *MockExternalConstraint[I, F]) Twelve(ctx context.Context) <-chan []I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", ctx) + ret0, _ := ret[0].(<-chan []I) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), ctx) +} + // Two mocks base method. func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { m.ctrl.T.Helper() @@ -210,32 +256,46 @@ func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eight(arg0 interface{}) *gomock. return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eight), arg0) } -// Five mocks base method. -func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { +// Eleven mocks base method. +func (m *MockEmbeddingIface[T, R]) Eleven() map[string]T { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Five", arg0) - ret0, _ := ret[0].(generics.Baz[R]) + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]T) return ret0 } -// Five indicates an expected call of Five. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 interface{}) *gomock.Call { +// Eleven indicates an expected call of Eleven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eleven() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eleven)) +} + +// First mocks base method. +func (m *MockEmbeddingIface[T, R]) First() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "First") + ret0, _ := ret[0].(R) + return ret0 } -// Foo mocks base method. -func (m *MockEmbeddingIface[T, R]) Foo() error { +// First indicates an expected call of First. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) First() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "First", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).First)) +} + +// Five mocks base method. +func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Foo") - ret0, _ := ret[0].(error) + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[R]) return ret0 } -// Foo indicates an expected call of Foo. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Foo() *gomock.Call { +// Five indicates an expected call of Five. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Foo", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Foo)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) } // Four mocks base method. @@ -252,6 +312,34 @@ func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Four(arg0 interface{}) *gomock.C return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Four), arg0) } +// Fourth mocks base method. +func (m *MockEmbeddingIface[T, R]) Fourth() generics.Generater[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fourth") + ret0, _ := ret[0].(generics.Generater[T]) + return ret0 +} + +// Fourth indicates an expected call of Fourth. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Fourth() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourth", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Fourth)) +} + +// Generate mocks base method. +func (m *MockEmbeddingIface[T, R]) Generate() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(R) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Generate)) +} + // Nine mocks base method. func (m *MockEmbeddingIface[T, R]) Nine(arg0 generics.Iface[T]) { m.ctrl.T.Helper() @@ -278,6 +366,35 @@ func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).One), arg0) } +// Read mocks base method. +func (m *MockEmbeddingIface[T, R]) Read(p []byte) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", p) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(p interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), p) +} + +// Second mocks base method. +func (m *MockEmbeddingIface[T, R]) Second() generics.StructType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Second") + ret0, _ := ret[0].(generics.StructType) + return ret0 +} + +// Second indicates an expected call of Second. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Second() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Second", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Second)) +} + // Seven mocks base method. func (m *MockEmbeddingIface[T, R]) Seven(arg0 T) other.One[T] { m.ctrl.T.Helper() @@ -318,75 +435,64 @@ func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Ten(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Ten), arg0) } -// Three mocks base method. -func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { +// Third mocks base method. +func (m *MockEmbeddingIface[T, R]) Third() other.Five { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Three", arg0) - ret0, _ := ret[0].(R) + ret := m.ctrl.Call(m, "Third") + ret0, _ := ret[0].(other.Five) return ret0 } -// Three indicates an expected call of Three. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 interface{}) *gomock.Call { +// Third indicates an expected call of Third. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Third() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Third", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Third)) } -// Twenty mocks base method. -func (m *MockEmbeddingIface[T, R]) Twenty(arg0 generics.StructType, arg1 T) (R, other.Five) { +// Thirteen mocks base method. +func (m *MockEmbeddingIface[T, R]) Thirteen(arg0 ...T) *R { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Twenty", arg0, arg1) - ret0, _ := ret[0].(R) - ret1, _ := ret[1].(other.Five) - return ret0, ret1 -} - -// Twenty indicates an expected call of Twenty. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twenty(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twenty", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twenty), arg0, arg1) -} - -// TwentyFour mocks base method. -func (m *MockEmbeddingIface[T, R]) TwentyFour() other.StructType { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TwentyFour") - ret0, _ := ret[0].(other.StructType) + varargs := []interface{}{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*R) return ret0 } -// TwentyFour indicates an expected call of TwentyFour. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) TwentyFour() *gomock.Call { +// Thirteen indicates an expected call of Thirteen. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Thirteen(arg0 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyFour", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).TwentyFour)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Thirteen), arg0...) } -// TwentyThree mocks base method. -func (m *MockEmbeddingIface[T, R]) TwentyThree(arg0 generics.TwentyTwo[R], arg1 generics.TwentyTwo[T]) other.StructType { +// Three mocks base method. +func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TwentyThree", arg0, arg1) - ret0, _ := ret[0].(other.StructType) + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(R) return ret0 } -// TwentyThree indicates an expected call of TwentyThree. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) TwentyThree(arg0, arg1 interface{}) *gomock.Call { +// Three indicates an expected call of Three. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyThree", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).TwentyThree), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) } -// TwentyTwo mocks base method. -func (m *MockEmbeddingIface[T, R]) TwentyTwo() generics.StructType { +// Twelve mocks base method. +func (m *MockEmbeddingIface[T, R]) Twelve(ctx context.Context) <-chan []T { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TwentyTwo") - ret0, _ := ret[0].(generics.StructType) + ret := m.ctrl.Call(m, "Twelve", ctx) + ret0, _ := ret[0].(<-chan []T) return ret0 } -// TwentyTwo indicates an expected call of TwentyTwo. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) TwentyTwo() *gomock.Call { +// Twelve indicates an expected call of Twelve. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyTwo", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).TwentyTwo)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), ctx) } // Two mocks base method. @@ -403,340 +509,91 @@ func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Two(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Two), arg0) } -// MockTwentyOne is a mock of TwentyOne interface. -type MockTwentyOne[T any] struct { - ctrl *gomock.Controller - recorder *MockTwentyOneMockRecorder[T] -} - -// MockTwentyOneMockRecorder is the mock recorder for MockTwentyOne. -type MockTwentyOneMockRecorder[T any] struct { - mock *MockTwentyOne[T] -} - -// NewMockTwentyOne creates a new mock instance. -func NewMockTwentyOne[T any](ctrl *gomock.Controller) *MockTwentyOne[T] { - mock := &MockTwentyOne[T]{ctrl: ctrl} - mock.recorder = &MockTwentyOneMockRecorder[T]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockTwentyOne[T]) EXPECT() *MockTwentyOneMockRecorder[T] { - return m.recorder -} - -// TwentyOne mocks base method. -func (m *MockTwentyOne[T]) TwentyOne() T { +// Water mocks base method. +func (m *MockEmbeddingIface[T, R]) Water(arg0 generics.Generater[T]) []generics.Generater[T] { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TwentyOne") - ret0, _ := ret[0].(T) + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]generics.Generater[T]) return ret0 } -// TwentyOne indicates an expected call of TwentyOne. -func (mr *MockTwentyOneMockRecorder[T]) TwentyOne() *gomock.Call { +// Water indicates an expected call of Water. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Water(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyOne", reflect.TypeOf((*MockTwentyOne[T])(nil).TwentyOne)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Water), arg0) } -// MockTwentyFour is a mock of TwentyFour interface. -type MockTwentyFour[T other.StructType] struct { +// MockGenerater is a mock of Generater interface. +type MockGenerater[T any] struct { ctrl *gomock.Controller - recorder *MockTwentyFourMockRecorder[T] + recorder *MockGeneraterMockRecorder[T] } -// MockTwentyFourMockRecorder is the mock recorder for MockTwentyFour. -type MockTwentyFourMockRecorder[T other.StructType] struct { - mock *MockTwentyFour[T] +// MockGeneraterMockRecorder is the mock recorder for MockGenerater. +type MockGeneraterMockRecorder[T any] struct { + mock *MockGenerater[T] } -// NewMockTwentyFour creates a new mock instance. -func NewMockTwentyFour[T other.StructType](ctrl *gomock.Controller) *MockTwentyFour[T] { - mock := &MockTwentyFour[T]{ctrl: ctrl} - mock.recorder = &MockTwentyFourMockRecorder[T]{mock} +// NewMockGenerater creates a new mock instance. +func NewMockGenerater[T any](ctrl *gomock.Controller) *MockGenerater[T] { + mock := &MockGenerater[T]{ctrl: ctrl} + mock.recorder = &MockGeneraterMockRecorder[T]{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockTwentyFour[T]) EXPECT() *MockTwentyFourMockRecorder[T] { +func (m *MockGenerater[T]) EXPECT() *MockGeneraterMockRecorder[T] { return m.recorder } -// TwentyFour mocks base method. -func (m *MockTwentyFour[T]) TwentyFour() T { +// Generate mocks base method. +func (m *MockGenerater[T]) Generate() T { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TwentyFour") + ret := m.ctrl.Call(m, "Generate") ret0, _ := ret[0].(T) return ret0 } -// TwentyFour indicates an expected call of TwentyFour. -func (mr *MockTwentyFourMockRecorder[T]) TwentyFour() *gomock.Call { +// Generate indicates an expected call of Generate. +func (mr *MockGeneraterMockRecorder[T]) Generate() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyFour", reflect.TypeOf((*MockTwentyFour[T])(nil).TwentyFour)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockGenerater[T])(nil).Generate)) } -// MockClonable is a mock of Clonable interface. -type MockClonable[T any] struct { +// MockGroup is a mock of Group interface. +type MockGroup[T generics.Generater[T]] struct { ctrl *gomock.Controller - recorder *MockClonableMockRecorder[T] + recorder *MockGroupMockRecorder[T] } -// MockClonableMockRecorder is the mock recorder for MockClonable. -type MockClonableMockRecorder[T any] struct { - mock *MockClonable[T] +// MockGroupMockRecorder is the mock recorder for MockGroup. +type MockGroupMockRecorder[T generics.Generater[T]] struct { + mock *MockGroup[T] } -// NewMockClonable creates a new mock instance. -func NewMockClonable[T any](ctrl *gomock.Controller) *MockClonable[T] { - mock := &MockClonable[T]{ctrl: ctrl} - mock.recorder = &MockClonableMockRecorder[T]{mock} +// NewMockGroup creates a new mock instance. +func NewMockGroup[T generics.Generater[T]](ctrl *gomock.Controller) *MockGroup[T] { + mock := &MockGroup[T]{ctrl: ctrl} + mock.recorder = &MockGroupMockRecorder[T]{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockClonable[T]) EXPECT() *MockClonableMockRecorder[T] { +func (m *MockGroup[T]) EXPECT() *MockGroupMockRecorder[T] { return m.recorder } -// Clone mocks base method. -func (m *MockClonable[T]) Clone() T { +// Join mocks base method. +func (m *MockGroup[T]) Join(ctx context.Context) ([]T, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Clone") - ret0, _ := ret[0].(T) - return ret0 -} - -// Clone indicates an expected call of Clone. -func (mr *MockClonableMockRecorder[T]) Clone() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clone", reflect.TypeOf((*MockClonable[T])(nil).Clone)) -} - -// MockFinder is a mock of Finder interface. -type MockFinder[T generics.Clonable[T]] struct { - ctrl *gomock.Controller - recorder *MockFinderMockRecorder[T] -} - -// MockFinderMockRecorder is the mock recorder for MockFinder. -type MockFinderMockRecorder[T generics.Clonable[T]] struct { - mock *MockFinder[T] -} - -// NewMockFinder creates a new mock instance. -func NewMockFinder[T generics.Clonable[T]](ctrl *gomock.Controller) *MockFinder[T] { - mock := &MockFinder[T]{ctrl: ctrl} - mock.recorder = &MockFinderMockRecorder[T]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockFinder[T]) EXPECT() *MockFinderMockRecorder[T] { - return m.recorder -} - -// Find mocks base method. -func (m *MockFinder[T]) Find(ctx context.Context) ([]T, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Find", ctx) + ret := m.ctrl.Call(m, "Join", ctx) ret0, _ := ret[0].([]T) ret1, _ := ret[1].(error) return ret0, ret1 } -// Find indicates an expected call of Find. -func (mr *MockFinderMockRecorder[T]) Find(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Find", reflect.TypeOf((*MockFinder[T])(nil).Find), ctx) -} - -// MockUpdateNotifier is a mock of UpdateNotifier interface. -type MockUpdateNotifier[T any] struct { - ctrl *gomock.Controller - recorder *MockUpdateNotifierMockRecorder[T] -} - -// MockUpdateNotifierMockRecorder is the mock recorder for MockUpdateNotifier. -type MockUpdateNotifierMockRecorder[T any] struct { - mock *MockUpdateNotifier[T] -} - -// NewMockUpdateNotifier creates a new mock instance. -func NewMockUpdateNotifier[T any](ctrl *gomock.Controller) *MockUpdateNotifier[T] { - mock := &MockUpdateNotifier[T]{ctrl: ctrl} - mock.recorder = &MockUpdateNotifierMockRecorder[T]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockUpdateNotifier[T]) EXPECT() *MockUpdateNotifierMockRecorder[T] { - return m.recorder -} - -// NotifyC mocks base method. -func (m *MockUpdateNotifier[T]) NotifyC(ctx context.Context) <-chan []T { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NotifyC", ctx) - ret0, _ := ret[0].(<-chan []T) - return ret0 -} - -// NotifyC indicates an expected call of NotifyC. -func (mr *MockUpdateNotifierMockRecorder[T]) NotifyC(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NotifyC", reflect.TypeOf((*MockUpdateNotifier[T])(nil).NotifyC), ctx) -} - -// Refresh mocks base method. -func (m *MockUpdateNotifier[T]) Refresh(ctx context.Context) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Refresh", ctx) -} - -// Refresh indicates an expected call of Refresh. -func (mr *MockUpdateNotifierMockRecorder[T]) Refresh(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Refresh", reflect.TypeOf((*MockUpdateNotifier[T])(nil).Refresh), ctx) -} - -// MockEmbeddedW is a mock of EmbeddedW interface. -type MockEmbeddedW[W generics.StructType] struct { - ctrl *gomock.Controller - recorder *MockEmbeddedWMockRecorder[W] -} - -// MockEmbeddedWMockRecorder is the mock recorder for MockEmbeddedW. -type MockEmbeddedWMockRecorder[W generics.StructType] struct { - mock *MockEmbeddedW[W] -} - -// NewMockEmbeddedW creates a new mock instance. -func NewMockEmbeddedW[W generics.StructType](ctrl *gomock.Controller) *MockEmbeddedW[W] { - mock := &MockEmbeddedW[W]{ctrl: ctrl} - mock.recorder = &MockEmbeddedWMockRecorder[W]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockEmbeddedW[W]) EXPECT() *MockEmbeddedWMockRecorder[W] { - return m.recorder -} - -// EmbeddedZ mocks base method. -func (m *MockEmbeddedW[W]) EmbeddedZ(arg0 W) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "EmbeddedZ", arg0) -} - -// EmbeddedZ indicates an expected call of EmbeddedZ. -func (mr *MockEmbeddedWMockRecorder[W]) EmbeddedZ(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedZ", reflect.TypeOf((*MockEmbeddedW[W])(nil).EmbeddedZ), arg0) -} - -// MockEmbeddedX is a mock of EmbeddedX interface. -type MockEmbeddedX[X generics.StructType] struct { - ctrl *gomock.Controller - recorder *MockEmbeddedXMockRecorder[X] -} - -// MockEmbeddedXMockRecorder is the mock recorder for MockEmbeddedX. -type MockEmbeddedXMockRecorder[X generics.StructType] struct { - mock *MockEmbeddedX[X] -} - -// NewMockEmbeddedX creates a new mock instance. -func NewMockEmbeddedX[X generics.StructType](ctrl *gomock.Controller) *MockEmbeddedX[X] { - mock := &MockEmbeddedX[X]{ctrl: ctrl} - mock.recorder = &MockEmbeddedXMockRecorder[X]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockEmbeddedX[X]) EXPECT() *MockEmbeddedXMockRecorder[X] { - return m.recorder -} - -// EmbeddedZ mocks base method. -func (m *MockEmbeddedX[X]) EmbeddedZ(arg0 X) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "EmbeddedZ", arg0) -} - -// EmbeddedZ indicates an expected call of EmbeddedZ. -func (mr *MockEmbeddedXMockRecorder[X]) EmbeddedZ(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedZ", reflect.TypeOf((*MockEmbeddedX[X])(nil).EmbeddedZ), arg0) -} - -// MockEmbeddedY is a mock of EmbeddedY interface. -type MockEmbeddedY[Y generics.StructType] struct { - ctrl *gomock.Controller - recorder *MockEmbeddedYMockRecorder[Y] -} - -// MockEmbeddedYMockRecorder is the mock recorder for MockEmbeddedY. -type MockEmbeddedYMockRecorder[Y generics.StructType] struct { - mock *MockEmbeddedY[Y] -} - -// NewMockEmbeddedY creates a new mock instance. -func NewMockEmbeddedY[Y generics.StructType](ctrl *gomock.Controller) *MockEmbeddedY[Y] { - mock := &MockEmbeddedY[Y]{ctrl: ctrl} - mock.recorder = &MockEmbeddedYMockRecorder[Y]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockEmbeddedY[Y]) EXPECT() *MockEmbeddedYMockRecorder[Y] { - return m.recorder -} - -// EmbeddedZ mocks base method. -func (m *MockEmbeddedY[Y]) EmbeddedZ(arg0 Y) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "EmbeddedZ", arg0) -} - -// EmbeddedZ indicates an expected call of EmbeddedZ. -func (mr *MockEmbeddedYMockRecorder[Y]) EmbeddedZ(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedZ", reflect.TypeOf((*MockEmbeddedY[Y])(nil).EmbeddedZ), arg0) -} - -// MockEmbeddedZ is a mock of EmbeddedZ interface. -type MockEmbeddedZ[Z any] struct { - ctrl *gomock.Controller - recorder *MockEmbeddedZMockRecorder[Z] -} - -// MockEmbeddedZMockRecorder is the mock recorder for MockEmbeddedZ. -type MockEmbeddedZMockRecorder[Z any] struct { - mock *MockEmbeddedZ[Z] -} - -// NewMockEmbeddedZ creates a new mock instance. -func NewMockEmbeddedZ[Z any](ctrl *gomock.Controller) *MockEmbeddedZ[Z] { - mock := &MockEmbeddedZ[Z]{ctrl: ctrl} - mock.recorder = &MockEmbeddedZMockRecorder[Z]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockEmbeddedZ[Z]) EXPECT() *MockEmbeddedZMockRecorder[Z] { - return m.recorder -} - -// EmbeddedZ mocks base method. -func (m *MockEmbeddedZ[Z]) EmbeddedZ(arg0 Z) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "EmbeddedZ", arg0) -} - -// EmbeddedZ indicates an expected call of EmbeddedZ. -func (mr *MockEmbeddedZMockRecorder[Z]) EmbeddedZ(arg0 interface{}) *gomock.Call { +// Join indicates an expected call of Join. +func (mr *MockGroupMockRecorder[T]) Join(ctx interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedZ", reflect.TypeOf((*MockEmbeddedZ[Z])(nil).EmbeddedZ), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), ctx) } diff --git a/mockgen/internal/tests/generics/source/mock_generics_test.go b/mockgen/internal/tests/generics/source/mock_generics_test.go index e577026..db27915 100644 --- a/mockgen/internal/tests/generics/source/mock_generics_test.go +++ b/mockgen/internal/tests/generics/source/mock_generics_test.go @@ -10,6 +10,7 @@ import ( gomock "go.uber.org/mock/gomock" generics "go.uber.org/mock/mockgen/internal/tests/generics" other "go.uber.org/mock/mockgen/internal/tests/generics/other" + constraints "golang.org/x/exp/constraints" ) // MockBar is a mock of Bar interface. @@ -291,21 +292,6 @@ func (mr *MockBarMockRecorder[T, R]) Twelve() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockBar[T, R])(nil).Twelve)) } -// Twenty mocks base method. -func (m *MockBar[T, R]) Twenty(arg0, arg1 any) (any, *other.Four) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Twenty", arg0, arg1) - ret0, _ := ret[0].(any) - ret1, _ := ret[1].(*other.Four) - return ret0, ret1 -} - -// Twenty indicates an expected call of Twenty. -func (mr *MockBarMockRecorder[T, R]) Twenty(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twenty", reflect.TypeOf((*MockBar[T, R])(nil).Twenty), arg0, arg1) -} - // Two mocks base method. func (m *MockBar[T, R]) Two(arg0 T) string { m.ctrl.T.Helper() @@ -343,39 +329,150 @@ func (m *MockIface[T]) EXPECT() *MockIfaceMockRecorder[T] { return m.recorder } -// MockTwentyTwo is a mock of TwentyTwo interface. -type MockTwentyTwo[T any] struct { +// MockUniverse is a mock of Universe interface. +type MockUniverse[T constraints.Signed] struct { + ctrl *gomock.Controller + recorder *MockUniverseMockRecorder[T] +} + +// MockUniverseMockRecorder is the mock recorder for MockUniverse. +type MockUniverseMockRecorder[T constraints.Signed] struct { + mock *MockUniverse[T] +} + +// NewMockUniverse creates a new mock instance. +func NewMockUniverse[T constraints.Signed](ctrl *gomock.Controller) *MockUniverse[T] { + mock := &MockUniverse[T]{ctrl: ctrl} + mock.recorder = &MockUniverseMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockUniverse[T]) EXPECT() *MockUniverseMockRecorder[T] { + return m.recorder +} + +// Water mocks base method. +func (m *MockUniverse[T]) Water(arg0 T) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockUniverseMockRecorder[T]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockUniverse[T])(nil).Water), arg0) +} + +// MockMilkyWay is a mock of MilkyWay interface. +type MockMilkyWay[R constraints.Integer] struct { + ctrl *gomock.Controller + recorder *MockMilkyWayMockRecorder[R] +} + +// MockMilkyWayMockRecorder is the mock recorder for MockMilkyWay. +type MockMilkyWayMockRecorder[R constraints.Integer] struct { + mock *MockMilkyWay[R] +} + +// NewMockMilkyWay creates a new mock instance. +func NewMockMilkyWay[R constraints.Integer](ctrl *gomock.Controller) *MockMilkyWay[R] { + mock := &MockMilkyWay[R]{ctrl: ctrl} + mock.recorder = &MockMilkyWayMockRecorder[R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockMilkyWay[R]) EXPECT() *MockMilkyWayMockRecorder[R] { + return m.recorder +} + +// Water mocks base method. +func (m *MockMilkyWay[R]) Water(arg0 R) []R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]R) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockMilkyWayMockRecorder[R]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockMilkyWay[R])(nil).Water), arg0) +} + +// MockSolarSystem is a mock of SolarSystem interface. +type MockSolarSystem[T constraints.Ordered] struct { + ctrl *gomock.Controller + recorder *MockSolarSystemMockRecorder[T] +} + +// MockSolarSystemMockRecorder is the mock recorder for MockSolarSystem. +type MockSolarSystemMockRecorder[T constraints.Ordered] struct { + mock *MockSolarSystem[T] +} + +// NewMockSolarSystem creates a new mock instance. +func NewMockSolarSystem[T constraints.Ordered](ctrl *gomock.Controller) *MockSolarSystem[T] { + mock := &MockSolarSystem[T]{ctrl: ctrl} + mock.recorder = &MockSolarSystemMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSolarSystem[T]) EXPECT() *MockSolarSystemMockRecorder[T] { + return m.recorder +} + +// Water mocks base method. +func (m *MockSolarSystem[T]) Water(arg0 T) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockSolarSystemMockRecorder[T]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockSolarSystem[T])(nil).Water), arg0) +} + +// MockEarth is a mock of Earth interface. +type MockEarth[R any] struct { ctrl *gomock.Controller - recorder *MockTwentyTwoMockRecorder[T] + recorder *MockEarthMockRecorder[R] } -// MockTwentyTwoMockRecorder is the mock recorder for MockTwentyTwo. -type MockTwentyTwoMockRecorder[T any] struct { - mock *MockTwentyTwo[T] +// MockEarthMockRecorder is the mock recorder for MockEarth. +type MockEarthMockRecorder[R any] struct { + mock *MockEarth[R] } -// NewMockTwentyTwo creates a new mock instance. -func NewMockTwentyTwo[T any](ctrl *gomock.Controller) *MockTwentyTwo[T] { - mock := &MockTwentyTwo[T]{ctrl: ctrl} - mock.recorder = &MockTwentyTwoMockRecorder[T]{mock} +// NewMockEarth creates a new mock instance. +func NewMockEarth[R any](ctrl *gomock.Controller) *MockEarth[R] { + mock := &MockEarth[R]{ctrl: ctrl} + mock.recorder = &MockEarthMockRecorder[R]{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockTwentyTwo[T]) EXPECT() *MockTwentyTwoMockRecorder[T] { +func (m *MockEarth[R]) EXPECT() *MockEarthMockRecorder[R] { return m.recorder } -// TwentyTwo mocks base method. -func (m *MockTwentyTwo[T]) TwentyTwo() T { +// Water mocks base method. +func (m *MockEarth[R]) Water(arg0 R) []R { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TwentyTwo") - ret0, _ := ret[0].(T) + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]R) return ret0 } -// TwentyTwo indicates an expected call of TwentyTwo. -func (mr *MockTwentyTwoMockRecorder[T]) TwentyTwo() *gomock.Call { +// Water indicates an expected call of Water. +func (mr *MockEarthMockRecorder[R]) Water(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TwentyTwo", reflect.TypeOf((*MockTwentyTwo[T])(nil).TwentyTwo)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEarth[R])(nil).Water), arg0) } From 74d04999b2c63a38c5daea282acfc728cd81f5cd Mon Sep 17 00:00:00 2001 From: wangyufeng Date: Tue, 11 Jul 2023 13:37:58 +0800 Subject: [PATCH 3/3] optimize test case --- go.mod | 9 +- go.sum | 18 +- mockgen/internal/tests/generics/external.go | 14 +- mockgen/internal/tests/generics/generics.go | 2 +- .../tests/generics/source/assert_test.go | 12 - .../generics/source/mock_external_mock.go | 598 +++++++++++++++++ .../generics/source/mock_external_test.go | 608 +----------------- ...generics_test.go => mock_generics_mock.go} | 0 8 files changed, 643 insertions(+), 618 deletions(-) delete mode 100644 mockgen/internal/tests/generics/source/assert_test.go create mode 100644 mockgen/internal/tests/generics/source/mock_external_mock.go rename mockgen/internal/tests/generics/source/{mock_generics_test.go => mock_generics_mock.go} (100%) diff --git a/go.mod b/go.mod index ccc412f..46b7097 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,11 @@ module go.uber.org/mock go 1.18 require ( - golang.org/x/mod v0.5.1 - golang.org/x/tools v0.1.8 + golang.org/x/mod v0.11.0 + golang.org/x/tools v0.2.0 ) require ( - github.com/yuin/goldmark v1.4.1 // indirect - golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + github.com/yuin/goldmark v1.4.13 // indirect + golang.org/x/sys v0.1.0 // indirect ) diff --git a/go.sum b/go.sum index 6255813..38c7646 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,8 @@ -github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w= -golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE= +golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= diff --git a/mockgen/internal/tests/generics/external.go b/mockgen/internal/tests/generics/external.go index 87c8c9a..a12c39f 100644 --- a/mockgen/internal/tests/generics/external.go +++ b/mockgen/internal/tests/generics/external.go @@ -8,7 +8,7 @@ import ( "golang.org/x/exp/constraints" ) -//go:generate mockgen --source=external.go --destination=source/mock_external_test.go --package source +//go:generate mockgen --source=external.go --destination=source/mock_external_mock.go --package source type ExternalConstraint[I constraints.Integer, F any] interface { One(string) string @@ -28,16 +28,16 @@ type ExternalConstraint[I constraints.Integer, F any] interface { type EmbeddingIface[T constraints.Integer, R constraints.Float] interface { io.Reader - Generater[R] - Earth[Generater[T]] - other.Either[R, StructType, other.Five, Generater[T]] + Generator[R] + Earth[Generator[T]] + other.Either[R, StructType, other.Five, Generator[T]] ExternalConstraint[T, R] } -type Generater[T any] interface { +type Generator[T any] interface { Generate() T } -type Group[T Generater[T]] interface { - Join(ctx context.Context) ([]T, error) +type Group[T Generator[any]] interface { + Join(ctx context.Context) []T } diff --git a/mockgen/internal/tests/generics/generics.go b/mockgen/internal/tests/generics/generics.go index 8a9778e..5ee5692 100644 --- a/mockgen/internal/tests/generics/generics.go +++ b/mockgen/internal/tests/generics/generics.go @@ -5,7 +5,7 @@ import ( "golang.org/x/exp/constraints" ) -//go:generate mockgen --source=generics.go --destination=source/mock_generics_test.go --package source +//go:generate mockgen --source=generics.go --destination=source/mock_generics_mock.go --package source ////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2 type Bar[T any, R any] interface { diff --git a/mockgen/internal/tests/generics/source/assert_test.go b/mockgen/internal/tests/generics/source/assert_test.go deleted file mode 100644 index ae825e7..0000000 --- a/mockgen/internal/tests/generics/source/assert_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package source - -import ( - "testing" - - "go.uber.org/mock/mockgen/internal/tests/generics" -) - -func TestAssert(t *testing.T) { - var x MockEmbeddingIface[int, float64] - var _ generics.EmbeddingIface[int, float64] = &x -} diff --git a/mockgen/internal/tests/generics/source/mock_external_mock.go b/mockgen/internal/tests/generics/source/mock_external_mock.go new file mode 100644 index 0000000..62f42d5 --- /dev/null +++ b/mockgen/internal/tests/generics/source/mock_external_mock.go @@ -0,0 +1,598 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: external.go + +// Package source is a generated GoMock package. +package source + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + generics "go.uber.org/mock/mockgen/internal/tests/generics" + other "go.uber.org/mock/mockgen/internal/tests/generics/other" + constraints "golang.org/x/exp/constraints" +) + +// MockExternalConstraint is a mock of ExternalConstraint interface. +type MockExternalConstraint[I constraints.Integer, F any] struct { + ctrl *gomock.Controller + recorder *MockExternalConstraintMockRecorder[I, F] +} + +// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. +type MockExternalConstraintMockRecorder[I constraints.Integer, F any] struct { + mock *MockExternalConstraint[I, F] +} + +// NewMockExternalConstraint creates a new mock instance. +func NewMockExternalConstraint[I constraints.Integer, F any](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { + mock := &MockExternalConstraint[I, F]{ctrl: ctrl} + mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[I, F]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) +} + +// Eleven mocks base method. +func (m *MockExternalConstraint[I, F]) Eleven() map[string]I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]I) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eleven)) +} + +// Five mocks base method. +func (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[F]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockExternalConstraint[I, F]) Four(arg0 I) generics.Foo[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[I, F]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0) +} + +// Nine mocks base method. +func (m *MockExternalConstraint[I, F]) Nine(arg0 generics.Iface[I]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockExternalConstraint[I, F]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0) +} + +// Seven mocks base method. +func (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[I]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockExternalConstraint[I, F]) Six(arg0 I) *generics.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[F]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockExternalConstraint[I, F]) Ten(arg0 *I) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) +} + +// Thirteen mocks base method. +func (m *MockExternalConstraint[I, F]) Thirteen(arg0 ...I) *F { + m.ctrl.T.Helper() + varargs := []interface{}{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*F) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockExternalConstraintMockRecorder[I, F]) Thirteen(arg0 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Thirteen), arg0...) +} + +// Three mocks base method. +func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(F) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockExternalConstraint[I, F]) Twelve(ctx context.Context) <-chan []I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", ctx) + ret0, _ := ret[0].(<-chan []I) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), ctx) +} + +// Two mocks base method. +func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) +} + +// MockEmbeddingIface is a mock of EmbeddingIface interface. +type MockEmbeddingIface[T constraints.Integer, R constraints.Float] struct { + ctrl *gomock.Controller + recorder *MockEmbeddingIfaceMockRecorder[T, R] +} + +// MockEmbeddingIfaceMockRecorder is the mock recorder for MockEmbeddingIface. +type MockEmbeddingIfaceMockRecorder[T constraints.Integer, R constraints.Float] struct { + mock *MockEmbeddingIface[T, R] +} + +// NewMockEmbeddingIface creates a new mock instance. +func NewMockEmbeddingIface[T constraints.Integer, R constraints.Float](ctrl *gomock.Controller) *MockEmbeddingIface[T, R] { + mock := &MockEmbeddingIface[T, R]{ctrl: ctrl} + mock.recorder = &MockEmbeddingIfaceMockRecorder[T, R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddingIface[T, R]) EXPECT() *MockEmbeddingIfaceMockRecorder[T, R] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockEmbeddingIface[T, R]) Eight(arg0 R) other.Two[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[T, R]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eight(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eight), arg0) +} + +// Eleven mocks base method. +func (m *MockEmbeddingIface[T, R]) Eleven() map[string]T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]T) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eleven)) +} + +// First mocks base method. +func (m *MockEmbeddingIface[T, R]) First() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "First") + ret0, _ := ret[0].(R) + return ret0 +} + +// First indicates an expected call of First. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) First() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "First", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).First)) +} + +// Five mocks base method. +func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[R]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockEmbeddingIface[T, R]) Four(arg0 T) generics.Foo[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[T, R]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Four(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Four), arg0) +} + +// Fourth mocks base method. +func (m *MockEmbeddingIface[T, R]) Fourth() generics.Generator[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fourth") + ret0, _ := ret[0].(generics.Generator[T]) + return ret0 +} + +// Fourth indicates an expected call of Fourth. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Fourth() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourth", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Fourth)) +} + +// Generate mocks base method. +func (m *MockEmbeddingIface[T, R]) Generate() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(R) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Generate)) +} + +// Nine mocks base method. +func (m *MockEmbeddingIface[T, R]) Nine(arg0 generics.Iface[T]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Nine(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockEmbeddingIface[T, R]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).One), arg0) +} + +// Read mocks base method. +func (m *MockEmbeddingIface[T, R]) Read(p []byte) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", p) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(p interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), p) +} + +// Second mocks base method. +func (m *MockEmbeddingIface[T, R]) Second() generics.StructType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Second") + ret0, _ := ret[0].(generics.StructType) + return ret0 +} + +// Second indicates an expected call of Second. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Second() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Second", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Second)) +} + +// Seven mocks base method. +func (m *MockEmbeddingIface[T, R]) Seven(arg0 T) other.One[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[T]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Seven(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockEmbeddingIface[T, R]) Six(arg0 T) *generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[R]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Six(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockEmbeddingIface[T, R]) Ten(arg0 *T) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Ten(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Ten), arg0) +} + +// Third mocks base method. +func (m *MockEmbeddingIface[T, R]) Third() other.Five { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Third") + ret0, _ := ret[0].(other.Five) + return ret0 +} + +// Third indicates an expected call of Third. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Third() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Third", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Third)) +} + +// Thirteen mocks base method. +func (m *MockEmbeddingIface[T, R]) Thirteen(arg0 ...T) *R { + m.ctrl.T.Helper() + varargs := []interface{}{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*R) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Thirteen(arg0 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Thirteen), arg0...) +} + +// Three mocks base method. +func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(R) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockEmbeddingIface[T, R]) Twelve(ctx context.Context) <-chan []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", ctx) + ret0, _ := ret[0].(<-chan []T) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), ctx) +} + +// Two mocks base method. +func (m *MockEmbeddingIface[T, R]) Two(arg0 T) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Two(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Two), arg0) +} + +// Water mocks base method. +func (m *MockEmbeddingIface[T, R]) Water(arg0 generics.Generator[T]) []generics.Generator[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]generics.Generator[T]) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Water), arg0) +} + +// MockGenerator is a mock of Generator interface. +type MockGenerator[T any] struct { + ctrl *gomock.Controller + recorder *MockGeneratorMockRecorder[T] +} + +// MockGeneratorMockRecorder is the mock recorder for MockGenerator. +type MockGeneratorMockRecorder[T any] struct { + mock *MockGenerator[T] +} + +// NewMockGenerator creates a new mock instance. +func NewMockGenerator[T any](ctrl *gomock.Controller) *MockGenerator[T] { + mock := &MockGenerator[T]{ctrl: ctrl} + mock.recorder = &MockGeneratorMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGenerator[T]) EXPECT() *MockGeneratorMockRecorder[T] { + return m.recorder +} + +// Generate mocks base method. +func (m *MockGenerator[T]) Generate() T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(T) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockGeneratorMockRecorder[T]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockGenerator[T])(nil).Generate)) +} + +// MockGroup is a mock of Group interface. +type MockGroup[T generics.Generator[any]] struct { + ctrl *gomock.Controller + recorder *MockGroupMockRecorder[T] +} + +// MockGroupMockRecorder is the mock recorder for MockGroup. +type MockGroupMockRecorder[T generics.Generator[any]] struct { + mock *MockGroup[T] +} + +// NewMockGroup creates a new mock instance. +func NewMockGroup[T generics.Generator[any]](ctrl *gomock.Controller) *MockGroup[T] { + mock := &MockGroup[T]{ctrl: ctrl} + mock.recorder = &MockGroupMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGroup[T]) EXPECT() *MockGroupMockRecorder[T] { + return m.recorder +} + +// Join mocks base method. +func (m *MockGroup[T]) Join(ctx context.Context) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Join", ctx) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Join indicates an expected call of Join. +func (mr *MockGroupMockRecorder[T]) Join(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), ctx) +} diff --git a/mockgen/internal/tests/generics/source/mock_external_test.go b/mockgen/internal/tests/generics/source/mock_external_test.go index 271698d..c345164 100644 --- a/mockgen/internal/tests/generics/source/mock_external_test.go +++ b/mockgen/internal/tests/generics/source/mock_external_test.go @@ -1,599 +1,41 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: external.go - -// Package source is a generated GoMock package. package source import ( - context "context" - reflect "reflect" + "context" + "testing" - gomock "go.uber.org/mock/gomock" - generics "go.uber.org/mock/mockgen/internal/tests/generics" - other "go.uber.org/mock/mockgen/internal/tests/generics/other" - constraints "golang.org/x/exp/constraints" + "go.uber.org/mock/gomock" + "go.uber.org/mock/mockgen/internal/tests/generics" ) -// MockExternalConstraint is a mock of ExternalConstraint interface. -type MockExternalConstraint[I constraints.Integer, F any] struct { - ctrl *gomock.Controller - recorder *MockExternalConstraintMockRecorder[I, F] -} - -// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. -type MockExternalConstraintMockRecorder[I constraints.Integer, F any] struct { - mock *MockExternalConstraint[I, F] -} - -// NewMockExternalConstraint creates a new mock instance. -func NewMockExternalConstraint[I constraints.Integer, F any](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { - mock := &MockExternalConstraint[I, F]{ctrl: ctrl} - mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] { - return m.recorder -} - -// Eight mocks base method. -func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eight", arg0) - ret0, _ := ret[0].(other.Two[I, F]) - return ret0 -} - -// Eight indicates an expected call of Eight. -func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) -} - -// Eleven mocks base method. -func (m *MockExternalConstraint[I, F]) Eleven() map[string]I { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eleven") - ret0, _ := ret[0].(map[string]I) - return ret0 -} - -// Eleven indicates an expected call of Eleven. -func (mr *MockExternalConstraintMockRecorder[I, F]) Eleven() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eleven)) -} - -// Five mocks base method. -func (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Five", arg0) - ret0, _ := ret[0].(generics.Baz[F]) - return ret0 -} - -// Five indicates an expected call of Five. -func (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0) -} - -// Four mocks base method. -func (m *MockExternalConstraint[I, F]) Four(arg0 I) generics.Foo[I, F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Four", arg0) - ret0, _ := ret[0].(generics.Foo[I, F]) - return ret0 -} - -// Four indicates an expected call of Four. -func (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0) -} - -// Nine mocks base method. -func (m *MockExternalConstraint[I, F]) Nine(arg0 generics.Iface[I]) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Nine", arg0) -} - -// Nine indicates an expected call of Nine. -func (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0) -} - -// One mocks base method. -func (m *MockExternalConstraint[I, F]) One(arg0 string) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "One", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// One indicates an expected call of One. -func (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0) -} - -// Seven mocks base method. -func (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Seven", arg0) - ret0, _ := ret[0].(other.One[I]) - return ret0 -} - -// Seven indicates an expected call of Seven. -func (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0) -} - -// Six mocks base method. -func (m *MockExternalConstraint[I, F]) Six(arg0 I) *generics.Baz[F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Six", arg0) - ret0, _ := ret[0].(*generics.Baz[F]) - return ret0 -} - -// Six indicates an expected call of Six. -func (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0) -} - -// Ten mocks base method. -func (m *MockExternalConstraint[I, F]) Ten(arg0 *I) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Ten", arg0) -} - -// Ten indicates an expected call of Ten. -func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) -} +func TestMockEmbeddingIface_One(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() -// Thirteen mocks base method. -func (m *MockExternalConstraint[I, F]) Thirteen(arg0 ...I) *F { - m.ctrl.T.Helper() - varargs := []interface{}{} - for _, a := range arg0 { - varargs = append(varargs, a) + m := NewMockEmbeddingIface[int, float64](ctrl) + m.EXPECT().One("foo").Return("bar") + if v := m.One("foo"); v != "bar" { + t.Errorf("One() = %v, want %v", v, "bar") } - ret := m.ctrl.Call(m, "Thirteen", varargs...) - ret0, _ := ret[0].(*F) - return ret0 -} - -// Thirteen indicates an expected call of Thirteen. -func (mr *MockExternalConstraintMockRecorder[I, F]) Thirteen(arg0 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Thirteen), arg0...) -} - -// Three mocks base method. -func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Three", arg0) - ret0, _ := ret[0].(F) - return ret0 -} - -// Three indicates an expected call of Three. -func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) -} - -// Twelve mocks base method. -func (m *MockExternalConstraint[I, F]) Twelve(ctx context.Context) <-chan []I { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Twelve", ctx) - ret0, _ := ret[0].(<-chan []I) - return ret0 -} - -// Twelve indicates an expected call of Twelve. -func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), ctx) -} - -// Two mocks base method. -func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Two", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// Two indicates an expected call of Two. -func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) -} - -// MockEmbeddingIface is a mock of EmbeddingIface interface. -type MockEmbeddingIface[T constraints.Integer, R constraints.Float] struct { - ctrl *gomock.Controller - recorder *MockEmbeddingIfaceMockRecorder[T, R] -} - -// MockEmbeddingIfaceMockRecorder is the mock recorder for MockEmbeddingIface. -type MockEmbeddingIfaceMockRecorder[T constraints.Integer, R constraints.Float] struct { - mock *MockEmbeddingIface[T, R] -} - -// NewMockEmbeddingIface creates a new mock instance. -func NewMockEmbeddingIface[T constraints.Integer, R constraints.Float](ctrl *gomock.Controller) *MockEmbeddingIface[T, R] { - mock := &MockEmbeddingIface[T, R]{ctrl: ctrl} - mock.recorder = &MockEmbeddingIfaceMockRecorder[T, R]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockEmbeddingIface[T, R]) EXPECT() *MockEmbeddingIfaceMockRecorder[T, R] { - return m.recorder -} - -// Eight mocks base method. -func (m *MockEmbeddingIface[T, R]) Eight(arg0 R) other.Two[T, R] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eight", arg0) - ret0, _ := ret[0].(other.Two[T, R]) - return ret0 -} - -// Eight indicates an expected call of Eight. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eight(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eight), arg0) -} - -// Eleven mocks base method. -func (m *MockEmbeddingIface[T, R]) Eleven() map[string]T { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eleven") - ret0, _ := ret[0].(map[string]T) - return ret0 -} - -// Eleven indicates an expected call of Eleven. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eleven() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eleven)) -} - -// First mocks base method. -func (m *MockEmbeddingIface[T, R]) First() R { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "First") - ret0, _ := ret[0].(R) - return ret0 -} - -// First indicates an expected call of First. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) First() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "First", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).First)) -} - -// Five mocks base method. -func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Five", arg0) - ret0, _ := ret[0].(generics.Baz[R]) - return ret0 -} - -// Five indicates an expected call of Five. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) } -// Four mocks base method. -func (m *MockEmbeddingIface[T, R]) Four(arg0 T) generics.Foo[T, R] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Four", arg0) - ret0, _ := ret[0].(generics.Foo[T, R]) - return ret0 -} - -// Four indicates an expected call of Four. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Four(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Four), arg0) -} +func TestMockUniverse_Water(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() -// Fourth mocks base method. -func (m *MockEmbeddingIface[T, R]) Fourth() generics.Generater[T] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Fourth") - ret0, _ := ret[0].(generics.Generater[T]) - return ret0 + m := NewMockUniverse[int](ctrl) + m.EXPECT().Water(1024) + m.Water(1024) } -// Fourth indicates an expected call of Fourth. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Fourth() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourth", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Fourth)) -} - -// Generate mocks base method. -func (m *MockEmbeddingIface[T, R]) Generate() R { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Generate") - ret0, _ := ret[0].(R) - return ret0 -} +func TestNewMockGroup_Join(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() -// Generate indicates an expected call of Generate. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Generate() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Generate)) -} - -// Nine mocks base method. -func (m *MockEmbeddingIface[T, R]) Nine(arg0 generics.Iface[T]) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Nine", arg0) -} - -// Nine indicates an expected call of Nine. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Nine(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Nine), arg0) -} - -// One mocks base method. -func (m *MockEmbeddingIface[T, R]) One(arg0 string) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "One", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// One indicates an expected call of One. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).One), arg0) -} - -// Read mocks base method. -func (m *MockEmbeddingIface[T, R]) Read(p []byte) (int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Read", p) - ret0, _ := ret[0].(int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(p interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), p) -} - -// Second mocks base method. -func (m *MockEmbeddingIface[T, R]) Second() generics.StructType { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Second") - ret0, _ := ret[0].(generics.StructType) - return ret0 -} - -// Second indicates an expected call of Second. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Second() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Second", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Second)) -} - -// Seven mocks base method. -func (m *MockEmbeddingIface[T, R]) Seven(arg0 T) other.One[T] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Seven", arg0) - ret0, _ := ret[0].(other.One[T]) - return ret0 -} - -// Seven indicates an expected call of Seven. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Seven(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Seven), arg0) -} - -// Six mocks base method. -func (m *MockEmbeddingIface[T, R]) Six(arg0 T) *generics.Baz[R] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Six", arg0) - ret0, _ := ret[0].(*generics.Baz[R]) - return ret0 -} - -// Six indicates an expected call of Six. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Six(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Six), arg0) -} - -// Ten mocks base method. -func (m *MockEmbeddingIface[T, R]) Ten(arg0 *T) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Ten", arg0) -} - -// Ten indicates an expected call of Ten. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Ten(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Ten), arg0) -} - -// Third mocks base method. -func (m *MockEmbeddingIface[T, R]) Third() other.Five { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Third") - ret0, _ := ret[0].(other.Five) - return ret0 -} - -// Third indicates an expected call of Third. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Third() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Third", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Third)) -} - -// Thirteen mocks base method. -func (m *MockEmbeddingIface[T, R]) Thirteen(arg0 ...T) *R { - m.ctrl.T.Helper() - varargs := []interface{}{} - for _, a := range arg0 { - varargs = append(varargs, a) + m := NewMockGroup[generics.Generator[any]](ctrl) + ctx := context.TODO() + m.EXPECT().Join(ctx).Return(nil) + if v := m.Join(ctx); v != nil { + t.Errorf("Join() = %v, want %v", v, nil) } - ret := m.ctrl.Call(m, "Thirteen", varargs...) - ret0, _ := ret[0].(*R) - return ret0 -} - -// Thirteen indicates an expected call of Thirteen. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Thirteen(arg0 ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Thirteen), arg0...) -} - -// Three mocks base method. -func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Three", arg0) - ret0, _ := ret[0].(R) - return ret0 -} - -// Three indicates an expected call of Three. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) -} - -// Twelve mocks base method. -func (m *MockEmbeddingIface[T, R]) Twelve(ctx context.Context) <-chan []T { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Twelve", ctx) - ret0, _ := ret[0].(<-chan []T) - return ret0 -} - -// Twelve indicates an expected call of Twelve. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), ctx) -} - -// Two mocks base method. -func (m *MockEmbeddingIface[T, R]) Two(arg0 T) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Two", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// Two indicates an expected call of Two. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Two(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Two), arg0) -} - -// Water mocks base method. -func (m *MockEmbeddingIface[T, R]) Water(arg0 generics.Generater[T]) []generics.Generater[T] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Water", arg0) - ret0, _ := ret[0].([]generics.Generater[T]) - return ret0 -} - -// Water indicates an expected call of Water. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Water(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Water), arg0) -} - -// MockGenerater is a mock of Generater interface. -type MockGenerater[T any] struct { - ctrl *gomock.Controller - recorder *MockGeneraterMockRecorder[T] -} - -// MockGeneraterMockRecorder is the mock recorder for MockGenerater. -type MockGeneraterMockRecorder[T any] struct { - mock *MockGenerater[T] -} - -// NewMockGenerater creates a new mock instance. -func NewMockGenerater[T any](ctrl *gomock.Controller) *MockGenerater[T] { - mock := &MockGenerater[T]{ctrl: ctrl} - mock.recorder = &MockGeneraterMockRecorder[T]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockGenerater[T]) EXPECT() *MockGeneraterMockRecorder[T] { - return m.recorder -} - -// Generate mocks base method. -func (m *MockGenerater[T]) Generate() T { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Generate") - ret0, _ := ret[0].(T) - return ret0 -} - -// Generate indicates an expected call of Generate. -func (mr *MockGeneraterMockRecorder[T]) Generate() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockGenerater[T])(nil).Generate)) -} - -// MockGroup is a mock of Group interface. -type MockGroup[T generics.Generater[T]] struct { - ctrl *gomock.Controller - recorder *MockGroupMockRecorder[T] -} - -// MockGroupMockRecorder is the mock recorder for MockGroup. -type MockGroupMockRecorder[T generics.Generater[T]] struct { - mock *MockGroup[T] -} - -// NewMockGroup creates a new mock instance. -func NewMockGroup[T generics.Generater[T]](ctrl *gomock.Controller) *MockGroup[T] { - mock := &MockGroup[T]{ctrl: ctrl} - mock.recorder = &MockGroupMockRecorder[T]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockGroup[T]) EXPECT() *MockGroupMockRecorder[T] { - return m.recorder -} - -// Join mocks base method. -func (m *MockGroup[T]) Join(ctx context.Context) ([]T, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Join", ctx) - ret0, _ := ret[0].([]T) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Join indicates an expected call of Join. -func (mr *MockGroupMockRecorder[T]) Join(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), ctx) } diff --git a/mockgen/internal/tests/generics/source/mock_generics_test.go b/mockgen/internal/tests/generics/source/mock_generics_mock.go similarity index 100% rename from mockgen/internal/tests/generics/source/mock_generics_test.go rename to mockgen/internal/tests/generics/source/mock_generics_mock.go