forked from mirror/cast
FIx ToStringMapStringSliceE
* Update caste.go bug fix json config, for example: { "test" : ["abc", "123"] } * update test
This commit is contained in:
parent
e31f36ffc9
commit
4532b05430
|
@ -108,6 +108,9 @@ func TestMaps(t *testing.T) {
|
|||
var stringMapStringSliceMultiple = map[string][]string{"key 1": []string{"value 1", "value 2", "value 3"}, "key 2": []string{"value 1", "value 2", "value 3"}, "key 3": []string{"value 1", "value 2", "value 3"}}
|
||||
var stringMapStringSliceSingle = map[string][]string{"key 1": []string{"value 1"}, "key 2": []string{"value 2"}, "key 3": []string{"value 3"}}
|
||||
|
||||
var stringMapInterface1 = map[string]interface{}{"key 1": []string{"value 1"}, "key 2": []string{"value 2"}}
|
||||
var stringMapInterfaceResult1 = map[string][]string{"key 1": []string{"value 1"}, "key 2": []string{"value 2"}}
|
||||
|
||||
assert.Equal(t, ToStringMap(taxonomies), map[string]interface{}{"tag": "tags", "group": "groups"})
|
||||
assert.Equal(t, ToStringMapBool(stringMapBool), map[string]bool{"v1": true, "v2": false})
|
||||
|
||||
|
@ -128,6 +131,7 @@ func TestMaps(t *testing.T) {
|
|||
assert.Equal(t, ToStringMapStringSlice(interfaceMapInterfaceSlice), stringMapStringSlice)
|
||||
assert.Equal(t, ToStringMapStringSlice(interfaceMapString), stringMapStringSingleSliceFieldsResult)
|
||||
assert.Equal(t, ToStringMapStringSlice(interfaceMapInterface), stringMapStringSingleSliceFieldsResult)
|
||||
assert.Equal(t, ToStringMapStringSlice(stringMapInterface1), stringMapInterfaceResult1)
|
||||
}
|
||||
|
||||
func TestSlices(t *testing.T) {
|
||||
|
|
9
caste.go
9
caste.go
|
@ -310,7 +310,14 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) {
|
|||
}
|
||||
case map[string]interface{}:
|
||||
for k, val := range v {
|
||||
m[ToString(k)] = []string{ToString(val)}
|
||||
switch vt := val.(type) {
|
||||
case []interface{}:
|
||||
m[ToString(k)] = ToStringSlice(vt)
|
||||
case []string:
|
||||
m[ToString(k)] = vt
|
||||
default:
|
||||
m[ToString(k)] = []string{ToString(val)}
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
case map[interface{}][]string:
|
||||
|
|
Loading…
Reference in New Issue