Fix cast package tests on linux/arm32

This commit is contained in:
Herman Slatman
2025-02-24 23:44:18 +01:00
parent 7efdfe5286
commit 86090128b1
2 changed files with 9 additions and 8 deletions

View File

@@ -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)

View File

@@ -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) {
@@ -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))
}
@@ -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))
@@ -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) })
}