From d476d65f7ba921f0080e0175a6a316d4e483157b Mon Sep 17 00:00:00 2001 From: Krouton Date: Mon, 30 Mar 2020 23:21:31 +0900 Subject: [PATCH] Parse parenthesized parameter-type. (#421) Add test. --- .../parenthesized_parameter_type/README.md | 3 ++ .../parenthesized_parameter_type/input.go | 5 +++ .../parenthesized_parameter_type/mock.go | 45 +++++++++++++++++++ mockgen/parse.go | 2 + 4 files changed, 55 insertions(+) create mode 100644 mockgen/internal/tests/parenthesized_parameter_type/README.md create mode 100644 mockgen/internal/tests/parenthesized_parameter_type/input.go create mode 100644 mockgen/internal/tests/parenthesized_parameter_type/mock.go diff --git a/mockgen/internal/tests/parenthesized_parameter_type/README.md b/mockgen/internal/tests/parenthesized_parameter_type/README.md new file mode 100644 index 00000000..fc816bdf --- /dev/null +++ b/mockgen/internal/tests/parenthesized_parameter_type/README.md @@ -0,0 +1,3 @@ +# Parenthesized Parameter Type + +Test for [Issue#416](https://github.com/golang/mock/issues/416). diff --git a/mockgen/internal/tests/parenthesized_parameter_type/input.go b/mockgen/internal/tests/parenthesized_parameter_type/input.go new file mode 100644 index 00000000..b9be61bd --- /dev/null +++ b/mockgen/internal/tests/parenthesized_parameter_type/input.go @@ -0,0 +1,5 @@ +package parenthesized_parameter_type + +type Example interface { + ParenthesizedParameterType(param *(int)) +} diff --git a/mockgen/internal/tests/parenthesized_parameter_type/mock.go b/mockgen/internal/tests/parenthesized_parameter_type/mock.go new file mode 100644 index 00000000..911df8d8 --- /dev/null +++ b/mockgen/internal/tests/parenthesized_parameter_type/mock.go @@ -0,0 +1,45 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./mockgen/internal/tests/parenthesized_parameter_type/input.go + +// Package parenthesized_parameter_type is a generated GoMock package. +package parenthesized_parameter_type + +import ( + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockExample is a mock of Example interface. +type MockExample struct { + ctrl *gomock.Controller + recorder *MockExampleMockRecorder +} + +// MockExampleMockRecorder is the mock recorder for MockExample. +type MockExampleMockRecorder struct { + mock *MockExample +} + +// NewMockExample creates a new mock instance. +func NewMockExample(ctrl *gomock.Controller) *MockExample { + mock := &MockExample{ctrl: ctrl} + mock.recorder = &MockExampleMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExample) EXPECT() *MockExampleMockRecorder { + return m.recorder +} + +// ParenthesizedParameterType mocks base method. +func (m *MockExample) ParenthesizedParameterType(param *int) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "ParenthesizedParameterType", param) +} + +// ParenthesizedParameterType indicates an expected call of ParenthesizedParameterType. +func (mr *MockExampleMockRecorder) ParenthesizedParameterType(param interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ParenthesizedParameterType", reflect.TypeOf((*MockExample)(nil).ParenthesizedParameterType), param) +} diff --git a/mockgen/parse.go b/mockgen/parse.go index 7f1a433c..f47a3d9a 100644 --- a/mockgen/parse.go +++ b/mockgen/parse.go @@ -424,6 +424,8 @@ func (p *fileParser) parseType(pkg string, typ ast.Expr) (model.Type, error) { return nil, p.errorf(v.Pos(), "can't handle non-empty unnamed struct types") } return model.PredeclaredType("struct{}"), nil + case *ast.ParenExpr: + return p.parseType(pkg, v.X) } return nil, fmt.Errorf("don't know how to parse type %T", typ)