diff --git a/cast_test.go b/cast_test.go index d9a1479..fe3ff9a 100644 --- a/cast_test.go +++ b/cast_test.go @@ -987,10 +987,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 { diff --git a/caste.go b/caste.go index 70c7291..d0ef605 100644 --- a/caste.go +++ b/caste.go @@ -1151,6 +1151,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()