Skip to content

Commit

Permalink
optimize test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tra4less committed Jul 9, 2023
1 parent 42810d3 commit 3aa6442
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 460 deletions.
53 changes: 13 additions & 40 deletions mockgen/internal/tests/generics/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package generics

import (
"context"
"io"

"go.uber.org/mock/mockgen/internal/tests/generics/other"
"golang.org/x/exp/constraints"
)

//go:generate mockgen --source=external.go --destination=source/mock_external_test.go --package source

type ExternalConstraint[I constraints.Integer, F constraints.Float] interface {
type ExternalConstraint[I constraints.Integer, F any] interface {
One(string) string
Two(I) string
Three(I) F
Expand All @@ -20,51 +21,23 @@ type ExternalConstraint[I constraints.Integer, F constraints.Float] interface {
Eight(F) other.Two[I, F]
Nine(Iface[I])
Ten(*I)
Eleven() map[string]I
Twelve(ctx context.Context) <-chan []I
Thirteen(...I) *F
}

type EmbeddingIface[T constraints.Integer, R constraints.Float] interface {
other.Twenty[T, StructType, R, other.Five]
TwentyTwo[StructType]
other.TwentyThree[TwentyTwo[R], TwentyTwo[T]]
TwentyFour[other.StructType]
Foo() error
io.Reader
Generater[R]
Earth[Generater[T]]
other.Either[R, StructType, other.Five, Generater[T]]
ExternalConstraint[T, R]
}

type TwentyOne[T any] interface {
TwentyOne() T
type Generater[T any] interface {
Generate() T
}

type TwentyFour[T other.StructType] interface {
TwentyFour() T
}

type Clonable[T any] interface {
Clone() T
}

type Finder[T Clonable[T]] interface {
Find(ctx context.Context) ([]T, error)
}

type UpdateNotifier[T any] interface {
NotifyC(ctx context.Context) <-chan []T

Refresh(ctx context.Context)
}

type EmbeddedW[W StructType] interface {
EmbeddedY[W]
}

type EmbeddedX[X StructType] interface {
EmbeddedY[X]
}

type EmbeddedY[Y StructType] interface {
EmbeddedZ[Y]
}

type EmbeddedZ[Z any] interface {
EmbeddedZ(Z)
type Group[T Generater[T]] interface {
Join(ctx context.Context) ([]T, error)
}
22 changes: 18 additions & 4 deletions mockgen/internal/tests/generics/generics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package generics

import "go.uber.org/mock/mockgen/internal/tests/generics/other"
import (
"go.uber.org/mock/mockgen/internal/tests/generics/other"
"golang.org/x/exp/constraints"
)

//go:generate mockgen --source=generics.go --destination=source/mock_generics_test.go --package source
////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2
Expand All @@ -25,7 +28,6 @@ type Bar[T any, R any] interface {
Seventeen() (*Foo[other.Three, other.Four], error)
Eighteen() (Iface[*other.Five], error)
Nineteen() AliasType
other.Twenty[any, any, any, *other.Four]
}

type Foo[T any, R any] struct{}
Expand All @@ -40,6 +42,18 @@ type StructType2 struct{}

type AliasType Baz[other.Three]

type TwentyTwo[T any] interface {
TwentyTwo() T
type Universe[T constraints.Signed] interface {
MilkyWay[T]
}

type MilkyWay[R constraints.Integer] interface {
SolarSystem[R]
}

type SolarSystem[T constraints.Ordered] interface {
Earth[T]
}

type Earth[R any] interface {
Water(R) []R
}
24 changes: 0 additions & 24 deletions mockgen/internal/tests/generics/go.sum
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
13 changes: 5 additions & 8 deletions mockgen/internal/tests/generics/other/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ type Four struct{}

type Five interface{}

type Twenty[R, S, T any, Z any] interface {
Twenty(S, R) (T, Z)
type Either[T, R, K, V any] interface {
First() T
Second() R
Third() K
Fourth() V
}

type TwentyThree[U, V any] interface {
TwentyThree(U, V) StructType
}

type StructType struct{}
2 changes: 1 addition & 1 deletion mockgen/internal/tests/generics/source/assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package source
import (
"testing"

"github.com/golang/mock/mockgen/internal/tests/generics"
"go.uber.org/mock/mockgen/internal/tests/generics"
)

func TestAssert(t *testing.T) {
Expand Down
Loading

0 comments on commit 3aa6442

Please sign in to comment.