Skip to content
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 VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.49
0.0.50
30 changes: 15 additions & 15 deletions mock/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,39 @@ const (
// a diff. The default, 3, means no context lines.
func Context(context int) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.Context(context)
mocks.diff.Context(context)
}
}

// FromFile sets the label to use for the "from" side of the diff. Default is
// `Want`.
func FromFile(file string) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.FromFile(file)
mocks.diff.FromFile(file)
}
}

// FromDate sets the label to use for the "from" date of the diff. Default is
// empty.
func FromDate(date string) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.FromDate(date)
mocks.diff.FromDate(date)
}
}

// ToFile sets the label to use for the "to" side of the diff. Default is
// `Got`.
func ToFile(file string) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.ToFile(file)
mocks.diff.ToFile(file)
}
}

// ToDate specifies the label to use for the "to" date of the diff. Default is
// empty.
func ToDate(date string) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.ToDate(date)
mocks.diff.ToDate(date)
}
}

Expand All @@ -68,7 +68,7 @@ func ToDate(date string) ConfigFunc {
// with `\t` or perhaps two spaces with ` `.
func Indent(indent string) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.Indent(indent)
mocks.diff.Indent(indent)
}
}

Expand All @@ -78,7 +78,7 @@ func Indent(indent string) ConfigFunc {
// specifically want to limit deeply nested structures.
func MaxDepth(maxDepth int) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.MaxDepth(maxDepth)
mocks.diff.MaxDepth(maxDepth)
}
}

Expand All @@ -87,7 +87,7 @@ func MaxDepth(maxDepth int) ConfigFunc {
// methods will not be invoked.
func DisableMethods(disable bool) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.DisableMethods(disable)
mocks.diff.DisableMethods(disable)
}
}

Expand All @@ -104,15 +104,15 @@ func DisableMethods(disable bool) ConfigFunc {
// or with the "safe" build tag specified.
func DisablePointerMethods(disable bool) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.DisablePointerMethods(disable)
mocks.diff.DisablePointerMethods(disable)
}
}

// DisablePointerAddresses sets whether to disable the printing of pointer
// addresses. This is useful when diffing data structures in tests.
func DisablePointerAddresses(disable bool) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.DisablePointerAddresses(disable)
mocks.diff.DisablePointerAddresses(disable)
}
}

Expand All @@ -121,7 +121,7 @@ func DisablePointerAddresses(disable bool) ConfigFunc {
// structures in tests.
func DisableCapacities(disable bool) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.DisableCapacities(disable)
mocks.diff.DisableCapacities(disable)
}
}

Expand All @@ -135,7 +135,7 @@ func DisableCapacities(disable bool) ConfigFunc {
// via the DisableMethods or DisablePointerMethods options.
func ContinueOnMethod(enable bool) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.ContinueOnMethod(enable)
mocks.diff.ContinueOnMethod(enable)
}
}

Expand All @@ -147,7 +147,7 @@ func ContinueOnMethod(enable bool) ConfigFunc {
// guarantees display stability.
func SortKeys(sort bool) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.SortKeys(sort)
mocks.diff.SortKeys(sort)
}
}

Expand All @@ -156,7 +156,7 @@ func SortKeys(sort bool) ConfigFunc {
// sorted (see `SortKeys`).
func SpewKeys(spew bool) ConfigFunc {
return func(mocks *Mocks) {
mocks.matcher.SpewKeys(spew)
mocks.diff.SpewKeys(spew)
}
}

Expand Down Expand Up @@ -382,7 +382,7 @@ type Equal struct {
// is a mismatch in the expected and actual values.
func (mocks *Mocks) Equal(want any) *Equal {
return &Equal{
config: mocks.matcher,
config: mocks.diff,
want: want,
diff: "",
}
Expand Down
6 changes: 3 additions & 3 deletions mock/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

const (
nameDiff = "diff"
nameDlib = "dlib"
nameSpew = "spew"
nameSpewTime = "spewTime"
nameMatcher = "matcher"
)

// diff creates the complete expected diff output in unified diff format. It
Expand All @@ -34,7 +34,7 @@ func GetDiffConfigAccessor(
mocks *mock.Mocks,
) reflect.Builder[*mock.DiffConfig] {
return reflect.NewAccessor(reflect.NewAccessor(mocks).
Get(nameMatcher).(*mock.DiffConfig))
Get(nameDiff).(*mock.DiffConfig))
}

type DiffParams struct {
Expand Down Expand Up @@ -454,7 +454,7 @@ var configTestCases = map[string]ConfigParams{
},
}

func TestMatcherConfig(t *testing.T) {
func TestConfig(t *testing.T) {
test.Map(t, configTestCases).
Run(func(t test.Test, param ConfigParams) {
// Given
Expand Down
14 changes: 7 additions & 7 deletions mock/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ type Mocks struct {
// A map of mock key value pairs.
args map[any]any

// Internal matcher settings.
matcher *DiffConfig
// Internal diff settings.
diff *DiffConfig
}

// NewMocks creates a new mock handler using given test reporter, e.g.
// [*testing.T], or [test.Test].
func NewMocks(t gomock.TestReporter, fncalls ...ConfigFunc) *Mocks {
return (&Mocks{
Ctrl: gomock.NewController(t),
wg: sync.NewLenientWaitGroup(),
mocks: map[reflect.Value]any{},
args: map[any]any{},
matcher: NewDiffConfig(),
Ctrl: gomock.NewController(t),
wg: sync.NewLenientWaitGroup(),
mocks: map[reflect.Value]any{},
args: map[any]any{},
diff: NewDiffConfig(),
}).Config(fncalls...).syncWith(t)
}

Expand Down
Loading