change ParseInt() to base 10

This commit is contained in:
Dan Burke 2021-05-05 23:24:05 -04:00
parent 8d17101741
commit 8341c35767
2 changed files with 37 additions and 5 deletions

View File

@ -301,6 +301,10 @@ func TestToIntE(t *testing.T) {
{true, 1, false},
{false, 0, false},
{"8", 8, false},
{"-8", -8, false},
{"0100", 100, false},
{"01234", 1234, false},
{"1234", 1234, false},
{nil, 0, false},
// errors
{"test", 0, true},
@ -346,6 +350,10 @@ func TestToInt64E(t *testing.T) {
{true, 1, false},
{false, 0, false},
{"8", 8, false},
{"-8", -8, false},
{"0100", 100, false},
{"01234", 1234, false},
{"1234", 1234, false},
{nil, 0, false},
// errors
{"test", 0, true},
@ -391,6 +399,10 @@ func TestToInt32E(t *testing.T) {
{true, 1, false},
{false, 0, false},
{"8", 8, false},
{"-8", -8, false},
{"0100", 100, false},
{"01234", 1234, false},
{"1234", 1234, false},
{nil, 0, false},
// errors
{"test", 0, true},
@ -436,6 +448,10 @@ func TestToInt16E(t *testing.T) {
{true, 1, false},
{false, 0, false},
{"8", 8, false},
{"-8", -8, false},
{"0100", 100, false},
{"01234", 1234, false},
{"1234", 1234, false},
{nil, 0, false},
// errors
{"test", 0, true},
@ -481,6 +497,10 @@ func TestToInt8E(t *testing.T) {
{true, 1, false},
{false, 0, false},
{"8", 8, false},
{"-8", -8, false},
{"0100", 100, false},
{"0124", 124, false},
{"114", 114, false},
{nil, 0, false},
// errors
{"test", 0, true},
@ -524,6 +544,12 @@ func TestToFloat64E(t *testing.T) {
{float32(8), 8, false},
{float64(8.31), 8.31, false},
{"8", 8, false},
{"-8", -8, false},
{"0100", 100, false},
{"01234", 1234, false},
{"01234.4", 1234.4, false},
{"1234", 1234, false},
{"1234.5", 1234.5, false},
{true, 1, false},
{false, 0, false},
// errors
@ -568,6 +594,12 @@ func TestToFloat32E(t *testing.T) {
{float32(8.31), 8.31, false},
{float64(8.31), 8.31, false},
{"8", 8, false},
{"-8", -8, false},
{"0100", 100, false},
{"01234", 1234, false},
{"01234.4", 1234.4, false},
{"1234", 1234, false},
{"1234.5", 1234.5, false},
{true, 1, false},
{false, 0, false},
// errors

View File

@ -211,7 +211,7 @@ func ToInt64E(i interface{}) (int64, error) {
case float32:
return int64(s), nil
case string:
v, err := strconv.ParseInt(s, 0, 0)
v, err := strconv.ParseInt(s, 10, 0)
if err == nil {
return v, nil
}
@ -258,7 +258,7 @@ func ToInt32E(i interface{}) (int32, error) {
case float32:
return int32(s), nil
case string:
v, err := strconv.ParseInt(s, 0, 0)
v, err := strconv.ParseInt(s, 10, 0)
if err == nil {
return int32(v), nil
}
@ -305,7 +305,7 @@ func ToInt16E(i interface{}) (int16, error) {
case float32:
return int16(s), nil
case string:
v, err := strconv.ParseInt(s, 0, 0)
v, err := strconv.ParseInt(s, 10, 0)
if err == nil {
return int16(v), nil
}
@ -352,7 +352,7 @@ func ToInt8E(i interface{}) (int8, error) {
case float32:
return int8(s), nil
case string:
v, err := strconv.ParseInt(s, 0, 0)
v, err := strconv.ParseInt(s, 10, 0)
if err == nil {
return int8(v), nil
}
@ -399,7 +399,7 @@ func ToIntE(i interface{}) (int, error) {
case float32:
return int(s), nil
case string:
v, err := strconv.ParseInt(s, 0, 0)
v, err := strconv.ParseInt(s, 10, 0)
if err == nil {
return int(v), nil
}