mock: improve doc (#1570)

## Summary
Improve API doc of package
[`mock`](https://pkg.go.dev/github.com/stretchr/testify/mock):
- add godoc links
- indent example code

## Motivation
Readability.
pull/1553/head^2
Olivier Mengué 2024-03-10 11:42:04 +01:00 committed by GitHub
parent 632a26080f
commit 3c302f75ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 11 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)}
} }
@ -819,8 +820,8 @@ func (f *FunctionalOptionsArgument) String() string {
return strings.Replace(fmt.Sprintf("%#v", f.value), "[]interface {}", name, 1) return strings.Replace(fmt.Sprintf("%#v", f.value), "[]interface {}", name, 1)
} }
// FunctionalOptions returns an FunctionalOptionsArgument object containing the functional option type // FunctionalOptions returns an [FunctionalOptionsArgument] object containing the functional option type
// and the values to check of // and the values to check of.
// //
// For example: // For example:
// Assert(t, FunctionalOptions("[]foo.FunctionalOption", foo.Opt1(), foo.Opt2())) // Assert(t, FunctionalOptions("[]foo.FunctionalOption", foo.Opt1(), foo.Opt2()))
@ -873,10 +874,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)