Add a nested data dir test

Ref. a discussion.
This commit is contained in:
Bjørn Erik Pedersen 2020-06-12 09:14:20 +02:00
parent 83d03a5201
commit e3e627e6b7
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -289,6 +289,23 @@ func TestDataDirCollidingMapsAndArrays(t *testing.T) {
doTestDataDir(t, dd, expected, "theme", "mytheme")
}
// https://discourse.gohugo.io/t/recursive-data-file-parsing/26192
func TestDataDirNestedDirectories(t *testing.T) {
t.Parallel()
var dd dataDir
dd.addSource("themes/mytheme/data/a.json", `["1", "2", "3"]`)
dd.addSource("data/test1/20/06/a.json", `{ "artist" : "Michael Brecker" }`)
dd.addSource("data/test1/20/05/b.json", `{ "artist" : "Charlie Parker" }`)
expected :=
map[string]interface{}{
"a": []interface{}{"1", "2", "3"},
"test1": map[string]interface{}{"20": map[string]interface{}{"05": map[string]interface{}{"b": map[string]interface{}{"artist": "Charlie Parker"}}, "06": map[string]interface{}{"a": map[string]interface{}{"artist": "Michael Brecker"}}}}}
doTestDataDir(t, dd, expected, "theme", "mytheme")
}
type dataDir struct {
sources [][2]string
}