-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor assertions to use generics #1308
base: master
Are you sure you want to change the base?
Conversation
5e6fe2d
to
661fad8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation puts much more compile-time constraints on types. I expect this will break existing code.
// assert.InDelta(t, math.Pi, 22/7.0, 0.01) | ||
func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { | ||
// assert.InDelta(t, math.Pi, 22/7.0, 0.01) | ||
func InDelta[T ConvertibleToFloat64](t TestingT, expected, actual T, delta float64, msgAndArgs ...interface{}) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InDelta should only take ~float32 | ~float64
. ConvertibleToFloat64
is too wide.
assert/assertions.go
Outdated
return Fail(t, fmt.Sprintf("Should be zero, but was %v", i), msgAndArgs...) | ||
} | ||
return true | ||
} | ||
|
||
// NotZero asserts that i is not the zero value for its type. | ||
func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool { | ||
func NotZero[T any](t TestingT, i T, msgAndArgs ...interface{}) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistency with Zero
where i
is ìnterface{}`.
Summary
Changes
Motivation
Related issues