hugolib: Re-enable YAML data tests disabled in f554503f
authorVas Sudanagunta <vas@commonkarma.org>
Sun, 11 Feb 2018 20:38:33 +0000 (15:38 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Feb 2018 16:14:40 +0000 (17:14 +0100)
Also gave basic tests for JSON, YAML and TOML identical inputs and expected outputs, a step toward JSON, YAML and TOML equivalency (see https://github.com/gohugoio/hugo/issues/4393#issuecomment-364437785).

hugolib/datafiles_test.go

index bf5d2106cbe075828ce9ea5c57652b8a5a06218a..4554d0a048f42e1ba182dd6a9263ae398df1b631 100644 (file)
@@ -36,44 +36,40 @@ func TestDataDirJSON(t *testing.T) {
        t.Parallel()
 
        sources := [][2]string{
-               {filepath.FromSlash("data/test/foo.json"), `{ "bar": "foofoo"  }`},
-               {filepath.FromSlash("data/test.json"), `{ "hello": [ { "world": "foo" } ] }`},
+               {filepath.FromSlash("data/test/a.json"), `{ "b" : { "c1": "red" , "c2": "blue" } }`},
        }
 
-       expected :=
-               map[string]interface{}{
-                       "test": map[string]interface{}{
-                               "hello": []interface{}{
-                                       map[string]interface{}{"world": "foo"},
-                               },
-                               "foo": map[string]interface{}{
-                                       "bar": "foofoo",
+       expected := map[string]interface{}{
+               "test": map[string]interface{}{
+                       "a": map[string]interface{}{
+                               "b": map[string]interface{}{
+                                       "c1": "red",
+                                       "c2": "blue",
                                },
                        },
-               }
+               },
+       }
 
        doTestDataDir(t, expected, sources)
 }
 
-// Enable / adjust in https://github.com/gohugoio/hugo/issues/4393
-func _TestDataDirYAML(t *testing.T) {
+func TestDataDirYAML(t *testing.T) {
        t.Parallel()
 
        sources := [][2]string{
-               {"data/test/a.yaml", "b:\n  c1: 1\n  c2: 2"},
+               {"data/test/a.yaml", "b:\n  c1: red\n  c2: blue"},
        }
 
-       expected :=
-               map[string]interface{}{
-                       "test": map[string]interface{}{
-                               "a": map[string]interface{}{
-                                       "b": map[interface{}]interface{}{
-                                               "c1": 1,
-                                               "c2": 2,
-                                       },
+       expected := map[string]interface{}{
+               "test": map[string]interface{}{
+                       "a": map[string]interface{}{
+                               "b": map[string]interface{}{
+                                       "c1": "red",
+                                       "c2": "blue",
                                },
                        },
-               }
+               },
+       }
 
        doTestDataDir(t, expected, sources)
 }
@@ -82,34 +78,31 @@ func TestDataDirToml(t *testing.T) {
        t.Parallel()
 
        sources := [][2]string{
-               {"data/test/kung.toml", "[foo]\nbar = 1"},
+               {"data/test/a.toml", "[b]\nc1 = \"red\"\nc2 = \"blue\"\n"},
        }
 
-       expected :=
-               map[string]interface{}{
-                       "test": map[string]interface{}{
-                               "kung": map[string]interface{}{
-                                       "foo": map[string]interface{}{
-                                               "bar": 1,
-                                       },
+       expected := map[string]interface{}{
+               "test": map[string]interface{}{
+                       "a": map[string]interface{}{
+                               "b": map[string]interface{}{
+                                       "c1": "red",
+                                       "c2": "blue",
                                },
                        },
-               }
+               },
+       }
 
        doTestDataDir(t, expected, sources)
 }
 
-// Enable / adjust in https://github.com/gohugoio/hugo/issues/4393
-func _TestDataDirYAML2(t *testing.T) {
+func TestDataDirJSON2(t *testing.T) {
        t.Parallel()
 
        sources := [][2]string{
-               {filepath.FromSlash("data/test/foo.yaml"), "bar: foofoo"},
-               {filepath.FromSlash("data/test.yaml"), "hello:\n- world: foo"},
+               {filepath.FromSlash("data/test/foo.json"), `{ "bar": "foofoo"  }`},
+               {filepath.FromSlash("data/test.json"), `{ "hello": [ { "world": "foo" } ] }`},
        }
 
-       //This is what we want: consistent use of map[string]interface{} for nested YAML maps
-       // the same as TestDataDirJSON
        expected :=
                map[string]interface{}{
                        "test": map[string]interface{}{
@@ -122,21 +115,32 @@ func _TestDataDirYAML2(t *testing.T) {
                        },
                }
 
-       // what we are actually getting as of v0.34
-       expectedV0_34 :=
+       doTestDataDir(t, expected, sources)
+}
+
+func TestDataDirYAML2(t *testing.T) {
+       t.Parallel()
+
+       sources := [][2]string{
+               {filepath.FromSlash("data/test/foo.yaml"), "bar: foofoo"},
+               {filepath.FromSlash("data/test.yaml"), "hello:\n- world: foo"},
+       }
+
+       //This is what we want: consistent use of map[string]interface{} for nested YAML maps
+       // the same as TestDataDirJSON
+       expected :=
                map[string]interface{}{
                        "test": map[string]interface{}{
                                "hello": []interface{}{
-                                       map[interface{}]interface{}{"world": "foo"},
+                                       map[string]interface{}{"world": "foo"},
                                },
                                "foo": map[string]interface{}{
                                        "bar": "foofoo",
                                },
                        },
                }
-       _ = expected
 
-       doTestDataDir(t, expectedV0_34, sources)
+       doTestDataDir(t, expected, sources)
 }
 
 func TestDataDirToml2(t *testing.T) {