Compare commits

...

3 Commits

Author SHA1 Message Date
blacktop 4aed3ebd8a
Merge c234700549 into 48ddde5701 2023-11-30 09:59:52 -07:00
blacktop c234700549
Merge remote-tracking branch 'upstream/master' 2023-05-16 11:14:24 -06:00
blacktop 2bb369afb4
fix issue where ToUintE fails to parse uint bigger than math.MaxInt64 2022-08-30 18:29:03 -06:00
2 changed files with 14 additions and 28 deletions

View File

@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"html/template"
"math"
"path"
"reflect"
"testing"
@ -109,7 +110,7 @@ func TestToUintE(t *testing.T) {
}
func TestToUint64E(t *testing.T) {
tests := createNumberTestSteps(uint64(0), uint64(1), uint64(8), uint64(0), uint64(8), uint64(8))
tests := createNumberTestSteps(uint64(0), uint64(1), uint64(8), uint64(0), uint64(8), uint64(math.MaxUint64))
runNumberTest(
qt.New(t),
@ -120,7 +121,7 @@ func TestToUint64E(t *testing.T) {
}
func TestToUint32E(t *testing.T) {
tests := createNumberTestSteps(uint32(0), uint32(1), uint32(8), uint32(0), uint32(8), uint32(8))
tests := createNumberTestSteps(uint32(0), uint32(1), uint32(8), uint32(0), uint32(8), uint32(math.MaxUint32))
runNumberTest(
qt.New(t),
@ -131,7 +132,7 @@ func TestToUint32E(t *testing.T) {
}
func TestToUint16E(t *testing.T) {
tests := createNumberTestSteps(uint16(0), uint16(1), uint16(8), uint16(0), uint16(8), uint16(8))
tests := createNumberTestSteps(uint16(0), uint16(1), uint16(8), uint16(0), uint16(8), uint16(math.MaxUint16))
runNumberTest(
qt.New(t),
@ -142,7 +143,7 @@ func TestToUint16E(t *testing.T) {
}
func TestToUint8E(t *testing.T) {
tests := createNumberTestSteps(uint8(0), uint8(1), uint8(8), uint8(0), uint8(8), uint8(8))
tests := createNumberTestSteps(uint8(0), uint8(1), uint8(8), uint8(0), uint8(8), uint8(math.MaxUint8))
runNumberTest(
qt.New(t),
@ -163,7 +164,7 @@ func TestToIntE(t *testing.T) {
}
func TestToInt64E(t *testing.T) {
tests := createNumberTestSteps(int64(0), int64(1), int64(8), int64(-8), int64(8), int64(-8))
tests := createNumberTestSteps(int64(0), int64(1), int64(8), int64(-8), int64(math.MaxInt64), int64(math.MinInt64))
runNumberTest(
qt.New(t),
@ -174,7 +175,7 @@ func TestToInt64E(t *testing.T) {
}
func TestToInt32E(t *testing.T) {
tests := createNumberTestSteps(int32(0), int32(1), int32(8), int32(-8), int32(8), int32(-8))
tests := createNumberTestSteps(int32(0), int32(1), int32(8), int32(-8), int32(math.MaxInt32), int32(math.MinInt32))
runNumberTest(
qt.New(t),
@ -185,7 +186,7 @@ func TestToInt32E(t *testing.T) {
}
func TestToInt16E(t *testing.T) {
tests := createNumberTestSteps(int16(0), int16(1), int16(8), int16(-8), int16(8), int16(-8))
tests := createNumberTestSteps(int16(0), int16(1), int16(8), int16(-8), int16(math.MaxInt16), int16(math.MinInt16))
runNumberTest(
qt.New(t),
@ -196,7 +197,7 @@ func TestToInt16E(t *testing.T) {
}
func TestToInt8E(t *testing.T) {
tests := createNumberTestSteps(int8(0), int8(1), int8(8), int8(-8), int8(8), int8(-8))
tests := createNumberTestSteps(int8(0), int8(1), int8(8), int8(-8), int8(math.MaxInt8), int8(math.MinInt8))
runNumberTest(
qt.New(t),

View File

@ -522,11 +522,8 @@ func ToUintE(i interface{}) (uint, error) {
switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseUint(trimZeroDecimal(s), 0, 0)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
}
return uint(v), nil
}
return 0, fmt.Errorf("unable to cast %#v of type %T to uint", i, i)
@ -598,11 +595,8 @@ func ToUint64E(i interface{}) (uint64, error) {
switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseUint(trimZeroDecimal(s), 0, 64)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
}
return uint64(v), nil
}
return 0, fmt.Errorf("unable to cast %#v of type %T to uint64", i, i)
@ -674,11 +668,8 @@ func ToUint32E(i interface{}) (uint32, error) {
switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseUint(trimZeroDecimal(s), 0, 32)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
}
return uint32(v), nil
}
return 0, fmt.Errorf("unable to cast %#v of type %T to uint32", i, i)
@ -750,11 +741,8 @@ func ToUint16E(i interface{}) (uint16, error) {
switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseUint(trimZeroDecimal(s), 0, 16)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
}
return uint16(v), nil
}
return 0, fmt.Errorf("unable to cast %#v of type %T to uint16", i, i)
@ -826,11 +814,8 @@ func ToUint8E(i interface{}) (uint8, error) {
switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseUint(trimZeroDecimal(s), 0, 8)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
}
return uint8(v), nil
}
return 0, fmt.Errorf("unable to cast %#v of type %T to uint8", i, i)