Skip to content

Commit

Permalink
doc: add links
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrre committed Nov 21, 2023
1 parent 1f18b0a commit 3f6027f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// ReportFunc is a function that is called when an assertion fails.
//
// It is implemented by testing.TB.Fatal|Error|Skip|Log.
// It is implemented by [testing.TB.Fatal]|[testing.TB.Error]|[testing.TB.Skip]|[testing.TB.Log].
type ReportFunc func(args ...any)

// Fail handles assertion failure.
Expand Down
4 changes: 2 additions & 2 deletions bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// BytesEqual asserts that b1 and b2 are equal.
// It uses bytes.Equal to compare the two byte slices.
// It uses [bytes.Equal] to compare the two byte slices.
func BytesEqual(tb testing.TB, b1, b2 []byte, opts ...Option) bool {
tb.Helper()
ok := bytes.Equal(b1, b2)
Expand All @@ -23,7 +23,7 @@ func BytesEqual(tb testing.TB, b1, b2 []byte, opts ...Option) bool {
}

// BytesNotEqual asserts that b1 and b2 are not equal.
// It uses bytes.Equal to compare the two byte slices.
// It uses [bytes.Equal] to compare the two byte slices.
func BytesNotEqual(tb testing.TB, b1, b2 []byte, opts ...Option) bool {
tb.Helper()
ok := !bytes.Equal(b1, b2)
Expand Down
4 changes: 2 additions & 2 deletions deep_equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var DeepEqualer = func(v1, v2 any) (diff string, equal bool) {
return diff, false
}

// DeepEqual asserts that v1 and v2 are deep equal according to DeepEqualer.
// DeepEqual asserts that v1 and v2 are deep equal according to [DeepEqualer].
func DeepEqual[T any](tb testing.TB, v1, v2 T, opts ...Option) bool {
tb.Helper()
diff, equal := DeepEqualer(v1, v2)
Expand All @@ -37,7 +37,7 @@ func DeepEqual[T any](tb testing.TB, v1, v2 T, opts ...Option) bool {
return ok
}

// NotDeepEqual asserts that v1 and v2 are not deep equal according to DeepEqualer.
// NotDeepEqual asserts that v1 and v2 are not deep equal according to [DeepEqualer].
func NotDeepEqual[T any](tb testing.TB, v1, v2 T, opts ...Option) bool {
tb.Helper()
_, equal := DeepEqualer(v1, v2)
Expand Down
10 changes: 5 additions & 5 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NoError(tb testing.TB, err error, opts ...Option) bool {
return ok
}

// ErrorIs asserts that errors.Is(err, target) returns true.
// ErrorIs asserts that [errors.Is] returns true.
func ErrorIs(tb testing.TB, err, target error, opts ...Option) bool {
tb.Helper()
ok := errors.Is(err, target)
Expand All @@ -57,7 +57,7 @@ func ErrorIs(tb testing.TB, err, target error, opts ...Option) bool {
return ok
}

// ErrorNotIs asserts that errors.Is(err, target) returns false.
// ErrorNotIs asserts that [errors.Is] returns false.
func ErrorNotIs(tb testing.TB, err, target error, opts ...Option) bool {
tb.Helper()
ok := !errors.Is(err, target)
Expand All @@ -72,7 +72,7 @@ func ErrorNotIs(tb testing.TB, err, target error, opts ...Option) bool {
return ok
}

// ErrorAs asserts that errors.As(err, target) returns true.
// ErrorAs asserts that [errors.As] returns true.
func ErrorAs(tb testing.TB, err error, target any, opts ...Option) bool {
tb.Helper()
ok := errors.As(err, target)
Expand All @@ -87,7 +87,7 @@ func ErrorAs(tb testing.TB, err error, target any, opts ...Option) bool {
return ok
}

// ErrorEqual asserts that err.Error() is equal to message.
// ErrorEqual asserts that the result of [error.Error] is equal to message.
func ErrorEqual(tb testing.TB, err error, message string, opts ...Option) bool {
tb.Helper()
ok := err.Error() == message
Expand All @@ -102,7 +102,7 @@ func ErrorEqual(tb testing.TB, err error, message string, opts ...Option) bool {
return ok
}

// ErrorContains asserts that err.Error() contains substr.
// ErrorContains asserts that the result of [error.Error] contains substr.
func ErrorContains(tb testing.TB, err error, substr string, opts ...Option) bool {
tb.Helper()
ok := strings.Contains(err.Error(), substr)
Expand Down
12 changes: 6 additions & 6 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func buildOptions(tb testing.TB, opts []Option) *options {
// Option is an option for an assertion.
type Option func(*options)

// MessageTransform returns an Option that adds a message transform function.
// MessageTransform returns an [Option] that adds a message transform function.
// The function is called before the ReportFunc.
// If several function are added, they're called in order.
func MessageTransform(f func(msg string) string) Option {
Expand All @@ -33,37 +33,37 @@ func MessageTransform(f func(msg string) string) Option {
}
}

// Message returns an Option that sets the message.
// Message returns an [Option] that sets the message.
func Message(msg string) Option {
return MessageTransform(func(_ string) string {
return msg
})
}

// Messagef returns an Option that sets the formatted message.
// Messagef returns an [Option] that sets the formatted message.
func Messagef(format string, args ...any) Option {
return MessageTransform(func(_ string) string {
return fmt.Sprintf(format, args...)
})
}

// MessageWrap returns an Option that wraps the message.
// MessageWrap returns an [Option] that wraps the message.
// The final message is "<msg>: <original message>".
func MessageWrap(msg string) Option {
return MessageTransform(func(wrappedMsg string) string {
return msg + ": " + wrappedMsg
})
}

// MessageWrapf returns an Option that wraps the message.
// MessageWrapf returns an [Option] that wraps the message.
// The final message is "<format msg>: <original message>".
func MessageWrapf(format string, args ...any) Option {
return MessageTransform(func(wrappedMsg string) string {
return fmt.Sprintf(format, args...) + ": " + wrappedMsg
})
}

// Report returns an Option that sets the report function.
// Report returns an [Option] that sets the report function.
func Report(f ReportFunc) Option {
return func(o *options) {
o.report = f
Expand Down
2 changes: 1 addition & 1 deletion regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
)

// RegexpString is a type that can be either a *regexp.Regexp or a string.
// RegexpString is a type that can be either a [*regexp.Regexp] or a [string].
//
// If it's a string, it's automatically compiled to a *regexp.Regexp.
type RegexpString interface {
Expand Down

0 comments on commit 3f6027f

Please sign in to comment.