Add data tests
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 10 Aug 2016 06:51:57 +0000 (08:51 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 6 Sep 2016 15:32:20 +0000 (18:32 +0300)
Updates #2309

hugolib/datafiles_test.go

index 36325dc61881b3072d1f94e82484aa82f833c262..751c79ba5461bbb2a35d0b7b8168df664f0ce049 100644 (file)
@@ -16,10 +16,12 @@ package hugolib
 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) {
@@ -104,3 +106,25 @@ func doTestDataDir(t *testing.T, expected interface{}, sources []source.Input) {
                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)
+
+}