Skip to content

Commit 06e0199

Browse files
authored
Add interface alias support to cmg (#553)
* Add interface alias support to `cmg` - Add support for making mocks for exported aliases that point to interface types in the `cmg` tool. * Fix embedding generic interfaces * Make lint happy * Use cast with ok instead of type switch when type switch is not really needed
1 parent ce9ba75 commit 06e0199

File tree

14 files changed

+841
-40
lines changed

14 files changed

+841
-40
lines changed

mock/cmd/cmg/pkg/generate/_tests/extensive/aliased/imported.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ type (
66
Interface interface {
77
Imported(Type) Type
88
}
9+
10+
Generic[T any] interface {
11+
ImportedGeneric(T) T
12+
}
913
)

mock/cmd/cmg/pkg/generate/_tests/extensive/extensive.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,25 @@ type (
4343

4444
Embedded
4545
imported.Interface
46+
47+
EmbeddedGeneric[uint16, uint32]
48+
imported.Generic[rune]
4649
}
4750

4851
Embedded interface {
4952
Embedded(int8) int8
5053
}
5154

55+
EmbeddedGeneric[X, Y any] interface {
56+
EmbeddedGeneric(x X, y Y) (X, Y)
57+
}
58+
5259
Generic[K comparable, V ~int | bool | string, X, Y any] interface {
5360
Simple(k K, v V, x X, y Y) (K, V, X, Y)
5461
Complex(map[K]V, []X, *Y, Set[K]) (map[K]V, []X, *Y, Set[K])
62+
63+
EmbeddedGeneric[X, Y]
64+
imported.Generic[Y]
5565
}
5666

5767
Struct struct{ A, B int }
@@ -62,4 +72,9 @@ type (
6272
StructAlias = struct{ A, B int }
6373
IntSetAlias = Set[int]
6474
SetAlias[K comparable] = Set[K]
75+
76+
ExtensiveAlias = Extensive
77+
ImportedAlias = imported.Interface
78+
GenericAlias[K comparable, V ~int | bool | string, X, Y any] = Generic[K, V, X, Y]
79+
ConstrainedGenericAlias = Generic[string, IntAlias, float32, float64]
6580
)

0 commit comments

Comments
 (0)