Skip to content

Commit

Permalink
TestStringifyKeysOnMapWithEntriesRecursively
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Mar 19, 2018
1 parent bbe5d53 commit 44f2180
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions util.go
Expand Up @@ -11,6 +11,10 @@ func StringifyKeys(m map[interface{}]interface{}) (out map[string]interface{}) {
out = map[string]interface{}{}

for k, v := range m {
if x, ok := v.(map[interface{}]interface{}); ok {
v = StringifyKeys(x)
}

out[k.(string)] = v
}

Expand Down
22 changes: 22 additions & 0 deletions util_test.go
Expand Up @@ -31,3 +31,25 @@ func TestStringifyKeysOnMapWithEntries(t *testing.T) {
t.Errorf("Expected:\n %#+v\nGot:\n %#+v", expected, result)
}
}

func TestStringifyKeysOnMapWithEntriesRecursively(t *testing.T) {
m := map[interface{}]interface{}{
"foo": map[interface{}]interface{}{
"foo": "bar",
"baz": 123,
},
"baz": 123,
}
result := phpserialize.StringifyKeys(m)
expected := map[string]interface{}{
"foo": map[string]interface{}{
"foo": "bar",
"baz": 123,
},
"baz": 123,
}

if !reflect.DeepEqual(result, expected) {
t.Errorf("Expected:\n %#+v\nGot:\n %#+v", expected, result)
}
}

0 comments on commit 44f2180

Please sign in to comment.