This commit is contained in:
Ricardo Gerardi 2020-05-14 03:25:47 +00:00 committed by GitHub
commit 81dc6e591b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -987,10 +987,12 @@ func TestToIntSliceE(t *testing.T) {
{[]interface{}{1.2, 3.2}, []int{1, 3}, false}, {[]interface{}{1.2, 3.2}, []int{1, 3}, false},
{[]string{"2", "3"}, []int{2, 3}, false}, {[]string{"2", "3"}, []int{2, 3}, false},
{[2]string{"2", "3"}, []int{2, 3}, false}, {[2]string{"2", "3"}, []int{2, 3}, false},
{"2 3", []int{2, 3}, false},
// errors // errors
{nil, nil, true}, {nil, nil, true},
{testing.T{}, nil, true}, {testing.T{}, nil, true},
{[]string{"foo", "bar"}, nil, true}, {[]string{"foo", "bar"}, nil, true},
{"2 a", []int{}, true},
} }
for i, test := range tests { for i, test := range tests {

View File

@ -1151,6 +1151,8 @@ func ToIntSliceE(i interface{}) ([]int, error) {
switch v := i.(type) { switch v := i.(type) {
case []int: case []int:
return v, nil return v, nil
case string:
return ToIntSliceE(strings.Fields(v))
} }
kind := reflect.TypeOf(i).Kind() kind := reflect.TypeOf(i).Kind()