Skip to content

Commit

Permalink
fix: rename Fn to Cond
Browse files Browse the repository at this point in the history
  • Loading branch information
damianopetrungaro committed Aug 15, 2023
1 parent 7f5a4aa commit 749161e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions gomock/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ func (anyMatcher) String() string {
return "is anything"
}

type fnMatcher struct {
type condMatcher struct {
fn func(x any) bool
}

func (f fnMatcher) Matches(x any) bool {
return f.fn(x)
func (c condMatcher) Matches(x any) bool {
return c.fn(x)
}

func (fnMatcher) String() string {
func (condMatcher) String() string {
return "adheres to a custom condition"
}

Expand Down Expand Up @@ -292,14 +292,14 @@ func All(ms ...Matcher) Matcher { return allMatcher{ms} }
// Any returns a matcher that always matches.
func Any() Matcher { return anyMatcher{} }

// Fn returns a specialized matchers customizable for complex matching behaviour.
// Cond returns a specialized matchers customizable for complex matching behaviour.
// This is particularly useful in case you want to match over a field of a custom struct, or dynamic logic.
//
// Example usage:
//
// Fn(func(x any){return x.(int) == 1}).Matches(1) // returns true
// Fn(func(x any){return x.(int) == 2}).Matches(1) // returns false
func Fn(fn func(x any) bool) Matcher { return fnMatcher{fn} }
// Cond(func(x any){return x.(int) == 1}).Matches(1) // returns true
// Cond(func(x any){return x.(int) == 2}).Matches(1) // returns false
func Cond(fn func(x any) bool) Matcher { return condMatcher{fn} }

// Eq returns a matcher that matches on equality.
//
Expand Down
2 changes: 1 addition & 1 deletion gomock/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestMatchers(t *testing.T) {
[]e{[]string{"a", "b"}, A{"a", "b"}},
[]e{[]string{"a"}, A{"b"}},
},
{"test Fn", gomock.Fn(func(x any) bool { return x.(B).Name == "Dam" }), []e{B{Name: "Dam"}}, []e{B{Name: "Dave"}}},
{"test Cond", gomock.Cond(func(x any) bool { return x.(B).Name == "Dam" }), []e{B{Name: "Dam"}}, []e{B{Name: "Dave"}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion sample/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestExpectFnForeignFour(t *testing.T) {
defer ctrl.Finish()

mockIndex := NewMockIndex(ctrl)
mockIndex.EXPECT().ForeignFour(gomock.Fn(func(x any) bool {
mockIndex.EXPECT().ForeignFour(gomock.Cond(func(x any) bool {
four, ok := x.(imp_four.Imp4)
if !ok {
return false
Expand Down

0 comments on commit 749161e

Please sign in to comment.