Skip to content
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

Fix cast package tests on linux/arm32 #2190

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/cast/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func Int32[T signed](x T) int32 {
return i32
}

func SafeUint32(x int) (uint32, error) {
func SafeUint32[T signed](x T) (uint32, error) {
return safecast.ToUint32(x)
}

func Uint32(x int) uint32 {
func Uint32[T signed](x T) uint32 {
u32, err := SafeUint32(x)
if err != nil {
panic(err)
Expand Down
13 changes: 7 additions & 6 deletions internal/cast/cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestInt64ConvertsValues(t *testing.T) {
}

func TestInt64PanicsOnLargeValue(t *testing.T) {
require.Panics(t, func() { Int64(uint64(math.MaxInt + 1)) })
require.Panics(t, func() { Int64(uint64(math.MaxInt64 + 1)) })
}

func TestUint64ConvertsValues(t *testing.T) {
Expand All @@ -44,16 +44,16 @@ func TestInt32ConvertsValues(t *testing.T) {
}

func TestInt32PanicsOnTooSmallValue(t *testing.T) {
require.Panics(t, func() { Int32(math.MinInt32 - 1) })
require.Panics(t, func() { Int32(int64(math.MinInt32 - 1)) })
}

func TestInt32PanicsOnLargeValue(t *testing.T) {
require.Panics(t, func() { Int32(math.MaxInt32 + 1) })
require.Panics(t, func() { Int32(int64(math.MaxInt32 + 1)) })
}

func TestUint32ConvertsValues(t *testing.T) {
require.Equal(t, uint32(0), Uint32(0))
require.Equal(t, uint32(math.MaxUint32), Uint32(math.MaxUint32))
require.Equal(t, uint32(math.MaxUint32), Uint32(int64(math.MaxUint32)))
require.Equal(t, uint32(42), Uint32(42))
}

Expand All @@ -62,8 +62,9 @@ func TestUint32PanicsOnNegativeValue(t *testing.T) {
}

func TestUint32PanicsOnLargeValue(t *testing.T) {
require.Panics(t, func() { Uint32(math.MaxUint32 + 1) })
require.Panics(t, func() { Uint32(int64(math.MaxUint32 + 1)) })
}

func TestUint16ConvertsValues(t *testing.T) {
require.Equal(t, uint16(0), Uint16(0))
require.Equal(t, uint16(math.MaxUint16), Uint16(math.MaxUint16))
Expand All @@ -75,5 +76,5 @@ func TestUint16PanicsOnNegativeValue(t *testing.T) {
}

func TestUint16PanicsOnLargeValue(t *testing.T) {
require.Panics(t, func() { Uint16(math.MaxUint32 + 1) })
require.Panics(t, func() { Uint16(math.MaxUint16 + 1) })
}
Loading