Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add support for union types - Test generic generation against a single more complicated interface - Fix package namespacing on type arguments
- Loading branch information
Paul Cruickshank
committed
Apr 22, 2022
1 parent
a7cbd5c
commit e7e706c
Showing
4 changed files
with
236 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package constraints | ||
|
||
type Signed interface { | ||
~int | ||
} | ||
|
||
type Integer interface { | ||
~int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
package test | ||
|
||
type Constraint interface { | ||
int | ||
} | ||
import ( | ||
"io" | ||
|
||
type Generic[T Constraint] interface { | ||
Get() T | ||
} | ||
"github.com/vektra/mockery/v2/pkg/fixtures/constraints" | ||
) | ||
|
||
type GenericAny[T any] interface { | ||
Get() T | ||
type RequesterGenerics[ | ||
TAny any, | ||
TComparable comparable, | ||
TSigned constraints.Signed, // external constraint | ||
TIntf GetInt, // internal interface | ||
TExternalIntf io.Writer, // external interface | ||
TGenIntf GetGeneric[TSigned], // generic interface | ||
TInlineType interface{ ~int | ~uint }, // inlined interface constraints | ||
TInlineTypeGeneric interface { | ||
~int | GenericType[int, GetInt] | ||
comparable | ||
}, // inlined type constraints | ||
] interface { | ||
GenericArguments(TAny, TComparable) (TSigned, TIntf) | ||
GenericStructs(GenericType[TAny, TIntf]) GenericType[TSigned, TIntf] | ||
GenericAnonymousStructs(struct{ Type1 TExternalIntf }) struct { | ||
Type2 GenericType[string, EmbeddedGet[int]] | ||
} | ||
} | ||
|
||
type GenericComparable[T comparable] interface { | ||
Get() T | ||
type GenericType[T any, S GetInt] struct { | ||
Any T | ||
Some []S | ||
} | ||
|
||
type Embedded interface { | ||
Generic[int] | ||
} | ||
type GetInt interface{ Get() int } | ||
|
||
type GetGeneric[T constraints.Integer] interface{ Get() T } | ||
|
||
type EmbeddedGet[T constraints.Signed] interface{ GetGeneric[T] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.