mirror of https://github.com/spf13/cast.git
Compare commits
6 Commits
68eb9b7caa
...
6bf6c09440
Author | SHA1 | Date |
---|---|---|
Ricardo Gerardi | 6bf6c09440 | |
Steve Francia | 487df00934 | |
Steve Francia | 955c718bf6 | |
Milan Lesichkov | 184982508e | |
skyjerry | 6e9731d50e | |
Ricardo Gerardi | 5e269c4527 |
|
@ -1,6 +1,6 @@
|
|||
# cast
|
||||
|
||||
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spf13/cast/ci.yaml?branch=master&style=flat-square)](https://github.com/spf13/cast/actions/workflows/ci.yaml)
|
||||
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spf13/cast/test.yaml?branch=master&style=flat-square)](https://github.com/spf13/cast/actions/workflows/test.yaml)
|
||||
[![PkgGoDev](https://pkg.go.dev/badge/mod/github.com/spf13/cast)](https://pkg.go.dev/mod/github.com/spf13/cast)
|
||||
![Go Version](https://img.shields.io/badge/go%20version-%3E=1.16-61CFDD.svg?style=flat-square)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/cast?style=flat-square)](https://goreportcard.com/report/github.com/spf13/cast)
|
||||
|
|
|
@ -111,6 +111,12 @@ func TestToUintE(t *testing.T) {
|
|||
func TestToUint64E(t *testing.T) {
|
||||
tests := createNumberTestSteps(uint64(0), uint64(1), uint64(8), uint64(0), uint64(8), uint64(8))
|
||||
|
||||
// Maximum value of uint64
|
||||
tests = append(tests,
|
||||
testStep{"18446744073709551615", uint64(18446744073709551615), false},
|
||||
testStep{"18446744073709551616", uint64(0), true},
|
||||
)
|
||||
|
||||
runNumberTest(
|
||||
qt.New(t),
|
||||
tests,
|
||||
|
@ -648,10 +654,12 @@ func TestToIntSliceE(t *testing.T) {
|
|||
{[]interface{}{1.2, 3.2}, []int{1, 3}, false},
|
||||
{[]string{"2", "3"}, []int{2, 3}, false},
|
||||
{[2]string{"2", "3"}, []int{2, 3}, false},
|
||||
{"2 3", []int{2, 3}, false},
|
||||
// errors
|
||||
{nil, nil, true},
|
||||
{testing.T{}, nil, true},
|
||||
{[]string{"foo", "bar"}, nil, true},
|
||||
{"2 a", []int{}, true},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
|
|
6
caste.go
6
caste.go
|
@ -613,12 +613,12 @@ 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, 0)
|
||||
if err == nil {
|
||||
if v < 0 {
|
||||
return 0, errNegativeNotAllowed
|
||||
}
|
||||
return uint64(v), nil
|
||||
return v, nil
|
||||
}
|
||||
return 0, fmt.Errorf("unable to cast %#v of type %T to uint64", i, i)
|
||||
case json.Number:
|
||||
|
@ -1335,6 +1335,8 @@ func ToIntSliceE(i interface{}) ([]int, error) {
|
|||
switch v := i.(type) {
|
||||
case []int:
|
||||
return v, nil
|
||||
case string:
|
||||
return ToIntSliceE(strings.Fields(v))
|
||||
}
|
||||
|
||||
kind := reflect.TypeOf(i).Kind()
|
||||
|
|
Loading…
Reference in New Issue