From 6161abdf7ec0d6adfa8671113f2f25f941aafc08 Mon Sep 17 00:00:00 2001 From: Damiano Petrungaro Date: Tue, 15 Aug 2023 20:43:34 +0200 Subject: [PATCH] fix: rename Fn to Cond --- gomock/matchers.go | 16 ++++++++-------- gomock/matchers_test.go | 2 +- sample/user_test.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) 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..55856e3 100644 --- a/sample/user_test.go +++ b/sample/user_test.go @@ -195,12 +195,12 @@ func TestDoAndReturnSignature(t *testing.T) { }) } -func TestExpectFnForeignFour(t *testing.T) { +func TestExpectCondForeignFour(t *testing.T) { ctrl := gomock.NewController(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