2015-12-10 17:19:38 -05:00
|
|
|
// Copyright 2015 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2015-03-19 12:23:14 -04:00
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
2016-08-10 02:51:57 -04:00
|
|
|
"strings"
|
2015-03-19 12:23:14 -04:00
|
|
|
"testing"
|
2016-08-19 07:22:19 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/deps"
|
2017-02-04 22:20:06 -05:00
|
|
|
jww "github.com/spf13/jwalterweatherman"
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2018-02-09 06:32:45 -05:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2015-03-19 12:23:14 -04:00
|
|
|
)
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
func TestDataDir(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2018-02-11 16:27:47 -05:00
|
|
|
equivDataDirs := make([]dataDir, 3)
|
|
|
|
equivDataDirs[0].addSource("data/test/a.json", `{ "b" : { "c1": "red" , "c2": "blue" } }`)
|
|
|
|
equivDataDirs[1].addSource("data/test/a.yaml", "b:\n c1: red\n c2: blue")
|
|
|
|
equivDataDirs[2].addSource("data/test/a.toml", "[b]\nc1 = \"red\"\nc2 = \"blue\"\n")
|
2018-02-11 15:38:33 -05:00
|
|
|
expected := map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{
|
|
|
|
"c1": "red",
|
|
|
|
"c2": "blue",
|
2018-02-02 01:28:24 -05:00
|
|
|
},
|
|
|
|
},
|
2018-02-11 15:38:33 -05:00
|
|
|
},
|
|
|
|
}
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestEquivalentDataDirs(t, equivDataDirs, expected)
|
2018-02-02 01:28:24 -05:00
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
// Unable to enforce equivalency for int values as
|
|
|
|
// the JSON, YAML and TOML parsers return
|
|
|
|
// float64, int, int64 respectively. They all return
|
|
|
|
// float64 for float values though:
|
|
|
|
func TestDataDirNumeric(t *testing.T) {
|
2018-02-02 01:28:24 -05:00
|
|
|
t.Parallel()
|
2018-02-11 16:27:47 -05:00
|
|
|
equivDataDirs := make([]dataDir, 3)
|
|
|
|
equivDataDirs[0].addSource("data/test/a.json", `{ "b" : { "c1": 1.7 , "c2": 2.9 } }`)
|
|
|
|
equivDataDirs[1].addSource("data/test/a.yaml", "b:\n c1: 1.7\n c2: 2.9")
|
|
|
|
equivDataDirs[2].addSource("data/test/a.toml", "[b]\nc1 = 1.7\nc2 = 2.9\n")
|
2018-02-11 15:38:33 -05:00
|
|
|
expected := map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{
|
2018-02-11 16:27:47 -05:00
|
|
|
"c1": 1.7,
|
|
|
|
"c2": 2.9,
|
2018-02-02 01:28:24 -05:00
|
|
|
},
|
|
|
|
},
|
2018-02-11 15:38:33 -05:00
|
|
|
},
|
|
|
|
}
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestEquivalentDataDirs(t, equivDataDirs, expected)
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
func TestDataDirBoolean(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2018-02-11 16:27:47 -05:00
|
|
|
equivDataDirs := make([]dataDir, 3)
|
|
|
|
equivDataDirs[0].addSource("data/test/a.json", `{ "b" : { "c1": true , "c2": false } }`)
|
|
|
|
equivDataDirs[1].addSource("data/test/a.yaml", "b:\n c1: true\n c2: false")
|
|
|
|
equivDataDirs[2].addSource("data/test/a.toml", "[b]\nc1 = true\nc2 = false\n")
|
2018-02-11 15:38:33 -05:00
|
|
|
expected := map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[string]interface{}{
|
2018-02-11 16:27:47 -05:00
|
|
|
"c1": true,
|
|
|
|
"c2": false,
|
2018-02-02 01:28:24 -05:00
|
|
|
},
|
|
|
|
},
|
2018-02-11 15:38:33 -05:00
|
|
|
},
|
|
|
|
}
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestEquivalentDataDirs(t, equivDataDirs, expected)
|
2018-02-02 01:28:24 -05:00
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
func TestDataDirTwoFiles(t *testing.T) {
|
2018-02-02 01:28:24 -05:00
|
|
|
t.Parallel()
|
2018-02-11 19:10:49 -05:00
|
|
|
equivDataDirs := make([]dataDir, 3)
|
2018-02-02 01:28:24 -05:00
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
equivDataDirs[0].addSource("data/test/foo.json", `{ "bar": "foofoo" }`)
|
2018-02-11 19:10:49 -05:00
|
|
|
equivDataDirs[0].addSource("data/test.json", `{ "hello": [ "world", "foo" ] }`)
|
2018-02-02 01:28:24 -05:00
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
equivDataDirs[1].addSource("data/test/foo.yaml", "bar: foofoo")
|
2018-02-11 19:10:49 -05:00
|
|
|
equivDataDirs[1].addSource("data/test.yaml", "hello:\n- world\n- foo")
|
2018-02-02 01:28:24 -05:00
|
|
|
|
2018-02-11 19:10:49 -05:00
|
|
|
equivDataDirs[2].addSource("data/test/foo.toml", "bar = \"foofoo\"")
|
|
|
|
equivDataDirs[2].addSource("data/test.toml", "hello = [\"world\", \"foo\"]")
|
2018-02-11 15:38:33 -05:00
|
|
|
|
|
|
|
expected :=
|
2018-02-02 01:28:24 -05:00
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"hello": []interface{}{
|
2018-02-11 19:10:49 -05:00
|
|
|
"world",
|
|
|
|
"foo",
|
2018-02-02 01:28:24 -05:00
|
|
|
},
|
|
|
|
"foo": map[string]interface{}{
|
|
|
|
"bar": "foofoo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestEquivalentDataDirs(t, equivDataDirs, expected)
|
2018-02-02 01:28:24 -05:00
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
func TestDataDirOverriddenValue(t *testing.T) {
|
2018-02-02 01:28:24 -05:00
|
|
|
t.Parallel()
|
2018-02-11 16:27:47 -05:00
|
|
|
equivDataDirs := make([]dataDir, 3)
|
2018-02-02 01:28:24 -05:00
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
// filepath.Walk walks the files in lexical order, '/' comes before '.'. Simulate this:
|
|
|
|
equivDataDirs[0].addSource("data/a.json", `{"a": "1"}`)
|
|
|
|
equivDataDirs[0].addSource("data/test/v1.json", `{"v1-2": "2"}`)
|
|
|
|
equivDataDirs[0].addSource("data/test/v2.json", `{"v2": ["2", "3"]}`)
|
|
|
|
equivDataDirs[0].addSource("data/test.json", `{"v1": "1"}`)
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
equivDataDirs[1].addSource("data/a.yaml", "a: \"1\"")
|
|
|
|
equivDataDirs[1].addSource("data/test/v1.yaml", "v1-2: \"2\"")
|
|
|
|
equivDataDirs[1].addSource("data/test/v2.yaml", "v2:\n- \"2\"\n- \"3\"")
|
|
|
|
equivDataDirs[1].addSource("data/test.yaml", "v1: \"1\"")
|
2018-02-02 01:28:24 -05:00
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
equivDataDirs[2].addSource("data/a.toml", "a = \"1\"")
|
|
|
|
equivDataDirs[2].addSource("data/test/v1.toml", "v1-2 = \"2\"")
|
|
|
|
equivDataDirs[2].addSource("data/test/v2.toml", "v2 = [\"2\", \"3\"]")
|
|
|
|
equivDataDirs[2].addSource("data/test.toml", "v1 = \"1\"")
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{"a": "1"},
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"v1": map[string]interface{}{"v1-2": "2"},
|
|
|
|
"v2": map[string]interface{}{"v2": []interface{}{"2", "3"}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestEquivalentDataDirs(t, equivDataDirs, expected)
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-11 19:10:49 -05:00
|
|
|
// Issue #4361, #3890
|
|
|
|
func TestDataDirArrayAtTopLevelOfFile(t *testing.T) {
|
2018-02-02 01:28:24 -05:00
|
|
|
t.Parallel()
|
2018-02-11 19:10:49 -05:00
|
|
|
equivDataDirs := make([]dataDir, 2)
|
2018-02-02 01:28:24 -05:00
|
|
|
|
2018-02-11 19:10:49 -05:00
|
|
|
equivDataDirs[0].addSource("data/test.json", `[ { "hello": "world" }, { "what": "time" }, { "is": "lunch?" } ]`)
|
|
|
|
equivDataDirs[1].addSource("data/test.yaml", `
|
2018-02-02 01:28:24 -05:00
|
|
|
- hello: world
|
|
|
|
- what: time
|
|
|
|
- is: lunch?
|
2018-02-11 16:27:47 -05:00
|
|
|
`)
|
2018-02-02 01:28:24 -05:00
|
|
|
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": []interface{}{
|
2018-02-11 19:10:49 -05:00
|
|
|
map[string]interface{}{"hello": "world"},
|
|
|
|
map[string]interface{}{"what": "time"},
|
|
|
|
map[string]interface{}{"is": "lunch?"},
|
2018-02-02 01:28:24 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-11 19:10:49 -05:00
|
|
|
doTestEquivalentDataDirs(t, equivDataDirs, expected)
|
2018-02-02 01:28:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Issue #892
|
2015-03-19 12:23:14 -04:00
|
|
|
func TestDataDirMultipleSources(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
var dd dataDir
|
|
|
|
dd.addSource("data/test/first.yaml", "bar: 1")
|
|
|
|
dd.addSource("themes/mytheme/data/test/first.yaml", "bar: 2")
|
|
|
|
dd.addSource("data/test/second.yaml", "tender: 2")
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"first": map[string]interface{}{
|
|
|
|
"bar": 1,
|
|
|
|
},
|
|
|
|
"second": map[string]interface{}{
|
|
|
|
"tender": 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestDataDir(t, dd, expected,
|
2017-02-04 22:20:06 -05:00
|
|
|
"theme", "mytheme")
|
2015-03-19 12:23:14 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
// test (and show) the way values from four different sources,
|
|
|
|
// including theme data, commingle and override
|
2018-02-02 01:28:24 -05:00
|
|
|
func TestDataDirMultipleSourcesCommingled(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
var dd dataDir
|
|
|
|
dd.addSource("data/a.json", `{ "b1" : { "c1": "data/a" }, "b2": "data/a", "b3": ["x", "y", "z"] }`)
|
|
|
|
dd.addSource("themes/mytheme/data/a.json", `{ "b1": "mytheme/data/a", "b2": "mytheme/data/a", "b3": "mytheme/data/a" }`)
|
|
|
|
dd.addSource("themes/mytheme/data/a/b1.json", `{ "c1": "mytheme/data/a/b1", "c2": "mytheme/data/a/b1" }`)
|
|
|
|
dd.addSource("data/a/b1.json", `{ "c1": "data/a/b1" }`)
|
2018-02-02 01:28:24 -05:00
|
|
|
|
|
|
|
// Per handleDataFile() comment:
|
|
|
|
// 1. A theme uses the same key; the main data folder wins
|
|
|
|
// 2. A sub folder uses the same key: the sub folder wins
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b1": map[string]interface{}{
|
|
|
|
"c1": "data/a/b1",
|
|
|
|
"c2": "mytheme/data/a/b1",
|
|
|
|
},
|
|
|
|
"b2": "data/a",
|
|
|
|
"b3": []interface{}{"x", "y", "z"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestDataDir(t, dd, expected, "theme", "mytheme")
|
2018-02-02 01:28:24 -05:00
|
|
|
}
|
|
|
|
|
2018-02-11 18:34:03 -05:00
|
|
|
func TestDataDirCollidingChildArrays(t *testing.T) {
|
2018-02-02 01:28:24 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
var dd dataDir
|
|
|
|
dd.addSource("themes/mytheme/data/a/b2.json", `["Q", "R", "S"]`)
|
|
|
|
dd.addSource("data/a.json", `{ "b1" : "data/a", "b2" : ["x", "y", "z"] }`)
|
|
|
|
dd.addSource("data/a/b2.json", `["1", "2", "3"]`)
|
2018-02-02 01:28:24 -05:00
|
|
|
|
|
|
|
// Per handleDataFile() comment:
|
|
|
|
// 1. A theme uses the same key; the main data folder wins
|
|
|
|
// 2. A sub folder uses the same key: the sub folder wins
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b1": "data/a",
|
|
|
|
"b2": []interface{}{"1", "2", "3"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestDataDir(t, dd, expected, "theme", "mytheme")
|
2018-02-02 01:28:24 -05:00
|
|
|
}
|
|
|
|
|
2018-02-11 18:34:03 -05:00
|
|
|
func TestDataDirCollidingTopLevelArrays(t *testing.T) {
|
2018-02-02 01:28:24 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
var dd dataDir
|
|
|
|
dd.addSource("themes/mytheme/data/a/b1.json", `["x", "y", "z"]`)
|
|
|
|
dd.addSource("data/a/b1.json", `["1", "2", "3"]`)
|
2018-02-02 01:28:24 -05:00
|
|
|
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b1": []interface{}{"1", "2", "3"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
doTestDataDir(t, dd, expected, "theme", "mytheme")
|
|
|
|
}
|
|
|
|
|
2018-02-11 18:34:03 -05:00
|
|
|
func TestDataDirCollidingMapsAndArrays(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var dd dataDir
|
|
|
|
// on
|
|
|
|
dd.addSource("themes/mytheme/data/a.json", `["1", "2", "3"]`)
|
|
|
|
dd.addSource("themes/mytheme/data/b.json", `{ "film" : "Logan Lucky" }`)
|
|
|
|
dd.addSource("data/a.json", `{ "music" : "Queen's Rebuke" }`)
|
|
|
|
dd.addSource("data/b.json", `["x", "y", "z"]`)
|
|
|
|
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"music": "Queen's Rebuke",
|
|
|
|
},
|
|
|
|
"b": []interface{}{"x", "y", "z"},
|
|
|
|
}
|
|
|
|
|
|
|
|
doTestDataDir(t, dd, expected, "theme", "mytheme")
|
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
type dataDir struct {
|
|
|
|
sources [][2]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dataDir) addSource(path, content string) {
|
|
|
|
d.sources = append(d.sources, [2]string{path, content})
|
|
|
|
}
|
|
|
|
|
|
|
|
func doTestEquivalentDataDirs(t *testing.T, equivDataDirs []dataDir, expected interface{}, configKeyValues ...interface{}) {
|
|
|
|
for i, dd := range equivDataDirs {
|
|
|
|
err := doTestDataDirImpl(t, dd, expected, configKeyValues...)
|
|
|
|
if err != "" {
|
|
|
|
t.Errorf("equivDataDirs[%d]: %s", i, err)
|
|
|
|
}
|
|
|
|
}
|
2018-02-02 01:28:24 -05:00
|
|
|
}
|
|
|
|
|
2018-02-11 16:27:47 -05:00
|
|
|
func doTestDataDir(t *testing.T, dd dataDir, expected interface{}, configKeyValues ...interface{}) {
|
|
|
|
err := doTestDataDirImpl(t, dd, expected, configKeyValues...)
|
|
|
|
if err != "" {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func doTestDataDirImpl(t *testing.T, dd dataDir, expected interface{}, configKeyValues ...interface{}) (err string) {
|
2017-02-04 22:20:06 -05:00
|
|
|
var (
|
|
|
|
cfg, fs = newTestCfg()
|
|
|
|
)
|
|
|
|
|
|
|
|
for i := 0; i < len(configKeyValues); i += 2 {
|
|
|
|
cfg.Set(configKeyValues[i].(string), configKeyValues[i+1])
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2018-02-02 01:28:24 -05:00
|
|
|
logger = jww.NewNotepad(jww.LevelWarn, jww.LevelWarn, os.Stdout, ioutil.Discard, t.Name(), log.Ldate|log.Ltime)
|
2017-02-04 22:20:06 -05:00
|
|
|
depsCfg = deps.DepsCfg{Fs: fs, Cfg: cfg, Logger: logger}
|
|
|
|
)
|
|
|
|
|
|
|
|
writeSource(t, fs, filepath.Join("content", "dummy.md"), "content")
|
2018-02-11 16:27:47 -05:00
|
|
|
writeSourcesToSource(t, "", fs, dd.sources...)
|
2017-02-04 22:20:06 -05:00
|
|
|
|
|
|
|
expectBuildError := false
|
|
|
|
|
|
|
|
if ok, shouldFail := expected.(bool); ok && shouldFail {
|
|
|
|
expectBuildError = true
|
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
// trap and report panics as unmarshaling errors so that test suit can complete
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
// Capture the stack trace
|
|
|
|
buf := make([]byte, 10000)
|
|
|
|
runtime.Stack(buf, false)
|
|
|
|
t.Errorf("PANIC: %s\n\nStack Trace : %s", r, string(buf))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
s := buildSingleSiteExpected(t, expectBuildError, depsCfg, BuildCfg{SkipRender: true})
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
if !expectBuildError && !reflect.DeepEqual(expected, s.Data) {
|
2018-02-11 16:27:47 -05:00
|
|
|
// This disabled code detects the situation described in the WARNING message below.
|
|
|
|
// The situation seems to only occur for TOML data with integer values.
|
|
|
|
// Perhaps the TOML parser returns ints in another type.
|
|
|
|
// Re-enable temporarily to debug fails that should be passing.
|
|
|
|
// Re-enable permanently if reflect.DeepEqual is simply too strict.
|
|
|
|
/*
|
|
|
|
exp := fmt.Sprintf("%#v", expected)
|
|
|
|
got := fmt.Sprintf("%#v", s.Data)
|
|
|
|
if exp == got {
|
|
|
|
t.Logf("WARNING: reflect.DeepEqual returned FALSE for values that appear equal.\n"+
|
|
|
|
"Treating as equal for the purpose of the test, but this maybe should be investigated.\n"+
|
|
|
|
"Expected data:\n%v got\n%v\n\nExpected type structure:\n%#[1]v got\n%#[2]v", expected, s.Data)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
return fmt.Sprintf("Expected data:\n%v got\n%v\n\nExpected type structure:\n%#[1]v got\n%#[2]v", expected, s.Data)
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
2018-02-11 16:27:47 -05:00
|
|
|
|
|
|
|
return
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
2016-08-10 02:51:57 -04:00
|
|
|
|
|
|
|
func TestDataFromShortcode(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
var (
|
|
|
|
cfg, fs = newTestCfg()
|
|
|
|
)
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
writeSource(t, fs, "data/hugo.toml", "slogan = \"Hugo Rocks!\"")
|
|
|
|
writeSource(t, fs, "layouts/_default/single.html", `
|
2016-08-10 02:51:57 -04:00
|
|
|
* Slogan from template: {{ .Site.Data.hugo.slogan }}
|
|
|
|
* {{ .Content }}`)
|
2017-02-04 22:20:06 -05:00
|
|
|
writeSource(t, fs, "layouts/shortcodes/d.html", `{{ .Page.Site.Data.hugo.slogan }}`)
|
|
|
|
writeSource(t, fs, "content/c.md", `---
|
2016-08-10 02:51:57 -04:00
|
|
|
---
|
|
|
|
Slogan from shortcode: {{< d >}}
|
|
|
|
`)
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
2016-08-10 02:51:57 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
content := readSource(t, fs, "public/c/index.html")
|
2016-08-10 02:51:57 -04:00
|
|
|
require.True(t, strings.Contains(content, "Slogan from template: Hugo Rocks!"), content)
|
|
|
|
require.True(t, strings.Contains(content, "Slogan from shortcode: Hugo Rocks!"), content)
|
|
|
|
|
|
|
|
}
|