Browse Source

Added space separated string to IntSlice conversion

pull/97/head
Ricardo Gerardi 4 years ago
parent
commit
5e269c4527
2 changed files with 4 additions and 0 deletions
  1. +2
    -0
      cast_test.go
  2. +2
    -0
      caste.go

+ 2
- 0
cast_test.go View File

@@ -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 {


+ 2
- 0
caste.go View File

@@ -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()


Loading…
Cancel
Save