ref: 446e606a098aeacbaaf89a53c7addd33cd888a74
parent: 5b331a18d761fa897c08acf28fd7e2d498c3b1e9
author: Bjørn Erik Pedersen <[email protected]>
date: Wed Aug 10 04:51:57 EDT 2016
Add data tests Updates #2309
--- a/hugolib/datafiles_test.go
+++ b/hugolib/datafiles_test.go
@@ -16,10 +16,12 @@
import (
"path/filepath"
"reflect"
+ "strings"
"testing"
"github.com/spf13/hugo/parser"
"github.com/spf13/hugo/source"
+ "github.com/stretchr/testify/require"
)
func TestDataDirJSON(t *testing.T) {
@@ -103,4 +105,26 @@
if !reflect.DeepEqual(expected, s.Data) {
t.Errorf("Expected structure\n%#v got\n%#v", expected, s.Data)
}
+}
+
+func TestDataFromShortcode(t *testing.T) {
+ testCommonResetState()
+ writeSource(t, "data/hugo.toml", "slogan = \"Hugo Rocks!\"")
+ writeSource(t, "layouts/_default/single.html", `
+* Slogan from template: {{ .Site.Data.hugo.slogan }}
+* {{ .Content }}`)
+ writeSource(t, "layouts/shortcodes/d.html", `{{ .Page.Site.Data.hugo.slogan }}`)
+ writeSource(t, "content/c.md", `---
+---
+Slogan from shortcode: {{< d >}}
+`)
+
+ h, err := newHugoSitesDefaultLanguage()
+ require.NoError(t, err)
+ require.NoError(t, h.Build(BuildCfg{}))
+
+ content := readSource(t, "public/c/index.html")
+ require.True(t, strings.Contains(content, "Slogan from template: Hugo Rocks!"), content)
+ require.True(t, strings.Contains(content, "Slogan from shortcode: Hugo Rocks!"), content)
+
}