Skip to content

Commit

Permalink
Show support for pointer type replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinJSilk committed Feb 8, 2024
1 parent 4b08243 commit e724b8a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ packages:
ReplaceGenericSelf:
config:
replace-type:
- github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf[-T]=github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf
- github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf[-T]=github.com/vektra/mockery/v2/pkg/fixtures.*ReplaceGenericSelf
github.com/vektra/mockery/v2/pkg/fixtures/recursive_generation:
config:
recursive: True
Expand Down
6 changes: 6 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ If a type constraint needs to be removed and replaced with a type, target the co
mockery --replace-type github.com/vektra/mockery/v2/baz/internal/foo.InternalBaz[-T]=baz:github.com/vektra/mockery/v2/baz.Baz
```

When replacing a generic constraint, you can replace the type with a pointer by adding a '*' before the output type name.

```shell
mockery --replace-type github.com/vektra/mockery/v2/baz/internal/foo.InternalBaz[-T]=baz:github.com/vektra/mockery/v2/baz.*Baz
```

`packages` configuration
------------------------
:octicons-tag-24: v2.21.0
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func (s *GeneratorSuite) TestReplaceTypeGeneric() {
cfg := GeneratorConfig{InPackage: false, ReplaceType: []string{
"github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGeneric[-TImport]=github.com/vektra/mockery/v2/pkg/fixtures/redefined_type_b.B",
"github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGeneric[TConstraint]=github.com/vektra/mockery/v2/pkg/fixtures/constraints.Integer",
"github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf[-T]=github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf",
"github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf[-T]=github.com/vektra/mockery/v2/pkg/fixtures.*ReplaceGenericSelf",
}}

s.checkGenerationRegexWithConfig("generic.go", "ReplaceGeneric", cfg, []regexpExpected{
Expand All @@ -781,8 +781,8 @@ func (s *GeneratorSuite) TestReplaceTypeGeneric() {
s.checkGenerationRegexWithConfig("generic.go", "ReplaceGenericSelf", cfg, []regexpExpected{
// type ReplaceGenericSelf struct
{true, regexp.MustCompile(`type ReplaceGenericSelf struct`)},
// func (_m *ReplaceGenericSelf) A() ReplaceGenericSelf
{true, regexp.MustCompile(`func \(_m \*ReplaceGenericSelf\) A\(\) ReplaceGenericSelf`)},
// func (_m *ReplaceGenericSelf) A() *ReplaceGenericSelf
{true, regexp.MustCompile(`func \(_m \*ReplaceGenericSelf\) A\(\) \*ReplaceGenericSelf`)},
})
}

Expand Down

0 comments on commit e724b8a

Please sign in to comment.