diff --git a/gomock/matchers.go b/gomock/matchers.go index 84df3be..e73f66c 100644 --- a/gomock/matchers.go +++ b/gomock/matchers.go @@ -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" } @@ -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. // diff --git a/gomock/matchers_test.go b/gomock/matchers_test.go index 109d0a5..8de86a2 100644 --- a/gomock/matchers_test.go +++ b/gomock/matchers_test.go @@ -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) { diff --git a/sample/user_test.go b/sample/user_test.go index 7587134..24e7c8b 100644 --- a/sample/user_test.go +++ b/sample/user_test.go @@ -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