Merge branch 'master' into master

pull/1433/head
Snir Yehuda 2024-03-18 09:47:57 +02:00 committed by GitHub
commit da1e1476cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 9 deletions

View File

@ -764,7 +764,7 @@ const (
) )
// AnythingOfTypeArgument contains the type of an argument // AnythingOfTypeArgument contains the type of an argument
// for use when type checking. Used in Diff and Assert. // for use when type checking. Used in [Arguments.Diff] and [Arguments.Assert].
// //
// Deprecated: this is an implementation detail that must not be used. Use [AnythingOfType] instead. // Deprecated: this is an implementation detail that must not be used. Use [AnythingOfType] instead.
type AnythingOfTypeArgument = anythingOfTypeArgument type AnythingOfTypeArgument = anythingOfTypeArgument
@ -780,24 +780,25 @@ type anythingOfTypeArgument string
// //
// For example: // For example:
// //
// Assert(t, AnythingOfType("string"), AnythingOfType("int")) // args.Assert(t, AnythingOfType("string"), AnythingOfType("int"))
func AnythingOfType(t string) AnythingOfTypeArgument { func AnythingOfType(t string) AnythingOfTypeArgument {
return anythingOfTypeArgument(t) return anythingOfTypeArgument(t)
} }
// IsTypeArgument is a struct that contains the type of an argument // IsTypeArgument is a struct that contains the type of an argument
// for use when type checking. This is an alternative to AnythingOfType. // for use when type checking. This is an alternative to [AnythingOfType].
// Used in Diff and Assert. // Used in [Arguments.Diff] and [Arguments.Assert].
type IsTypeArgument struct { type IsTypeArgument struct {
t reflect.Type t reflect.Type
} }
// IsType returns an IsTypeArgument object containing the type to check for. // IsType returns an IsTypeArgument object containing the type to check for.
// You can provide a zero-value of the type to check. This is an // You can provide a zero-value of the type to check. This is an
// alternative to AnythingOfType. Used in Diff and Assert. // alternative to [AnythingOfType]. Used in [Arguments.Diff] and [Arguments.Assert].
// //
// For example: // For example:
// Assert(t, IsType(""), IsType(0)) //
// args.Assert(t, IsType(""), IsType(0))
func IsType(t interface{}) *IsTypeArgument { func IsType(t interface{}) *IsTypeArgument {
return &IsTypeArgument{t: reflect.TypeOf(t)} return &IsTypeArgument{t: reflect.TypeOf(t)}
} }
@ -874,10 +875,11 @@ func (f argumentMatcher) String() string {
// and false otherwise. // and false otherwise.
// //
// Example: // Example:
// m.On("Do", MatchedBy(func(req *http.Request) bool { return req.Host == "example.com" }))
// //
// |fn|, must be a function accepting a single argument (of the expected type) // m.On("Do", MatchedBy(func(req *http.Request) bool { return req.Host == "example.com" }))
// which returns a bool. If |fn| doesn't match the required signature, //
// fn must be a function accepting a single argument (of the expected type)
// which returns a bool. If fn doesn't match the required signature,
// MatchedBy() panics. // MatchedBy() panics.
func MatchedBy(fn interface{}) argumentMatcher { func MatchedBy(fn interface{}) argumentMatcher {
fnType := reflect.TypeOf(fn) fnType := reflect.TypeOf(fn)