Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle interfaces with generics #311

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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 Down
46 changes: 46 additions & 0 deletions fixtures/genericinterface/genericinterface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package genericinterface

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

type CustomTypeT any
type CustomTypeU any

// incorrect setup. this would fail
// //counterfeiter:generate . GenericInterfaceBad[T CustomType]
// type GenericInterfaceBad[T CustomTypeT] interface {
// ReturnT() T
// TakeT(T)
// TakeAndReturnT(T) T
// DoSomething()
// }

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

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

//counterfeiter:generate . GenericInterfaceMultipleTypes
type GenericInterfaceMultipleTypes[T CustomTypeT, U CustomTypeU] interface {
ReturnT() T
ReturnU() U
ReturnTAndU() (T, U)
TakeT(T)
TakeU(U)
TakeTAndU(T, U)
TakeAndReturnT(T) T
TakeAndReturnU(U) U
TakeAndReturnTAndU(T, U) (T, U)
TakeTAndReturnU(T) U
DoSomething()
}

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

Loading
Loading