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 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 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, ToStringMap(taxonomies), map[string]interface{}{"tag": "tags", "group": "groups"})
|
||||||
assert.Equal(t, ToStringMapBool(stringMapBool), map[string]bool{"v1": true, "v2": false})
|
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(interfaceMapInterfaceSlice), stringMapStringSlice)
|
||||||
assert.Equal(t, ToStringMapStringSlice(interfaceMapString), stringMapStringSingleSliceFieldsResult)
|
assert.Equal(t, ToStringMapStringSlice(interfaceMapString), stringMapStringSingleSliceFieldsResult)
|
||||||
assert.Equal(t, ToStringMapStringSlice(interfaceMapInterface), stringMapStringSingleSliceFieldsResult)
|
assert.Equal(t, ToStringMapStringSlice(interfaceMapInterface), stringMapStringSingleSliceFieldsResult)
|
||||||
|
assert.Equal(t, ToStringMapStringSlice(stringMapInterface1), stringMapInterfaceResult1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSlices(t *testing.T) {
|
func TestSlices(t *testing.T) {
|
||||||
|
|
7
caste.go
7
caste.go
|
@ -310,8 +310,15 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) {
|
||||||
}
|
}
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
for k, val := range v {
|
for k, val := range v {
|
||||||
|
switch vt := val.(type) {
|
||||||
|
case []interface{}:
|
||||||
|
m[ToString(k)] = ToStringSlice(vt)
|
||||||
|
case []string:
|
||||||
|
m[ToString(k)] = vt
|
||||||
|
default:
|
||||||
m[ToString(k)] = []string{ToString(val)}
|
m[ToString(k)] = []string{ToString(val)}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
case map[interface{}][]string:
|
case map[interface{}][]string:
|
||||||
for k, val := range v {
|
for k, val := range v {
|
||||||
|
|
Loading…
Reference in New Issue