parser: Rename stringifyYAMLMapKeys to stringifyMapKeys
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Feb 2018 16:32:42 +0000 (17:32 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Feb 2018 17:17:25 +0000 (18:17 +0100)
parser/frontmatter.go
parser/frontmatter_test.go

index 5ed3ec11d23f1eff3742a73367e70040bcdc80e8..c5aaf807a2c0f63411413a1ddf6e3cd9211d680b 100644 (file)
@@ -209,7 +209,7 @@ func HandleYAMLMetaData(datum []byte) (map[string]interface{}, error) {
        // gotten from `json`.
        if err == nil {
                for k, v := range m {
-                       m[k] = stringifyYAMLMapKeys(v)
+                       m[k] = stringifyMapKeys(v)
                }
        }
 
@@ -227,30 +227,30 @@ func HandleYAMLData(datum []byte) (interface{}, error) {
        // and change all maps to map[string]interface{} like we would've
        // gotten from `json`.
        if err == nil {
-               m = stringifyYAMLMapKeys(m)
+               m = stringifyMapKeys(m)
        }
 
        return m, err
 }
 
-// stringifyKeysMapValue recurses into in and changes all instances of
+// stringifyMapKeys recurses into in and changes all instances of
 // map[interface{}]interface{} to map[string]interface{}. This is useful to
 // work around the impedence mismatch between JSON and YAML unmarshaling that's
 // described here: https://github.com/go-yaml/yaml/issues/139
 //
 // Inspired by https://github.com/stripe/stripe-mock, MIT licensed
-func stringifyYAMLMapKeys(in interface{}) interface{} {
+func stringifyMapKeys(in interface{}) interface{} {
        switch in := in.(type) {
        case []interface{}:
                res := make([]interface{}, len(in))
                for i, v := range in {
-                       res[i] = stringifyYAMLMapKeys(v)
+                       res[i] = stringifyMapKeys(v)
                }
                return res
        case map[interface{}]interface{}:
                res := make(map[string]interface{})
                for k, v := range in {
-                       res[fmt.Sprintf("%v", k)] = stringifyYAMLMapKeys(v)
+                       res[fmt.Sprintf("%v", k)] = stringifyMapKeys(v)
                }
                return res
        default:
index 9ac9749515c187acee99f4aa9ec2a72fe48d6f07..4d28facb22d7ffcb8cbc6a5686edb1ce07a73f56 100644 (file)
@@ -353,7 +353,7 @@ func TestStringifyYAMLMapKeys(t *testing.T) {
        }
 
        for i, c := range cases {
-               res := stringifyYAMLMapKeys(c.input)
+               res := stringifyMapKeys(c.input)
                if !reflect.DeepEqual(res, c.want) {
                        t.Errorf("[%d] given %q\nwant: %q\n got: %q", i, c.input, c.want, res)
                }
@@ -387,7 +387,7 @@ func BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps(b *testing.B) {
        }
        b.ResetTimer()
        for i := 0; i < b.N; i++ {
-               stringifyYAMLMapKeys(maps[i])
+               stringifyMapKeys(maps[i])
        }
 }
 
@@ -429,7 +429,7 @@ func BenchmarkStringifyMapKeysIntegers(b *testing.B) {
        }
        b.ResetTimer()
        for i := 0; i < b.N; i++ {
-               stringifyYAMLMapKeys(maps[i])
+               stringifyMapKeys(maps[i])
        }
 }
 func doBenchmarkFrontmatter(b *testing.B, fileformat string, numTags int) {