Skip to content

Refactor assertions to use generics#1308

Draft
TheAndrew2115 wants to merge 4 commits intostretchr:masterfrom
TheAndrew2115:generics-support
Draft

Refactor assertions to use generics#1308
TheAndrew2115 wants to merge 4 commits intostretchr:masterfrom
TheAndrew2115:generics-support

Conversation

@TheAndrew2115
Copy link

Summary

Changes

Motivation

Related issues

@dolmen dolmen added this to the v2.0.0 milestone Jul 11, 2023
Copy link
Collaborator

@dolmen dolmen left a 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 {
Copy link
Collaborator

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.


// 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 {
Copy link
Collaborator

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{}`.

@dolmen dolmen added enhancement Breaking Change pkg-assert Change related to package testify/assert go1.19+ Change applies when running with go1.19+ generics labels Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking Change enhancement generics go1.19+ Change applies when running with go1.19+ pkg-assert Change related to package testify/assert

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants