Skip to content

Commit

Permalink
Fix cast package tests on linux/arm32
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Feb 24, 2025
1 parent 7efdfe5 commit 8609012
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
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) })
}

0 comments on commit 8609012

Please sign in to comment.