Skip to content

Commit

Permalink
handle interfaces with generics
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredmtterminus committed Dec 13, 2024
1 parent 27aec33 commit 9a80e3f
Show file tree
Hide file tree
Showing 7 changed files with 580 additions and 26 deletions.
7 changes: 5 additions & 2 deletions arguments/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func New(args []string, workingDir string, evaler Evaler, stater Stater) (*Parse
}

func (a *ParsedArguments) PrettyPrint() {
b, _ := json.Marshal(a)
b, _ := json.MarshalIndent(a, "", " ")
fmt.Println(string(b))
}

Expand All @@ -105,6 +105,7 @@ func (a *ParsedArguments) parseInterfaceName(packageMode bool, args []string) {
a.InterfaceName = fullyQualifiedInterface[len(fullyQualifiedInterface)-1]
} else {
a.InterfaceName = args[1]
a.InterfaceName = strings.Split(a.InterfaceName, "[")[0]
}
}

Expand Down Expand Up @@ -141,7 +142,8 @@ func (a *ParsedArguments) parseOutputPath(packageMode bool, workingDir string, o
if strings.HasSuffix(outputPath, ".go") {
outputPathIsFilename = true
}
snakeCaseName := strings.ToLower(camelRegexp.ReplaceAllString(a.FakeImplName, "${1}_${2}"))
fakeImplName := strings.Split(a.FakeImplName, "[")[0]
snakeCaseName := strings.ToLower(camelRegexp.ReplaceAllString(fakeImplName, "${1}_${2}"))

if outputPath != "" {
if !filepath.IsAbs(outputPath) {
Expand Down Expand Up @@ -187,6 +189,7 @@ func (a *ParsedArguments) parsePackagePath(packageMode bool, args []string) {
a.PackagePath = strings.Join(fullyQualifiedInterface[:len(fullyQualifiedInterface)-1], ".")
} else {
a.InterfaceName = args[1]
a.InterfaceName = strings.Split(a.InterfaceName, "[")[0]
}

if a.PackagePath == "" {
Expand Down
21 changes: 21 additions & 0 deletions fixtures/genericinterface/genericinterface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package genericinterface

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate

type CustomType any

//counterfeiter:generate . GenericInterface[T CustomType]
type GenericInterface[T CustomType] interface {
ReturnT() T
TakeT(T)
TakeAndReturnT(T) T
DoSomething()
}

//counterfeiter:generate . GenericInterface2
type GenericInterface2[T CustomType] interface {
ReturnT() T
TakeT(T)
TakeAndReturnT(T) T
DoSomething()
}

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

Loading

0 comments on commit 9a80e3f

Please sign in to comment.