tpl/transform: Add transform.Unmarshal func

Fixes #5428
This commit is contained in:
Bjørn Erik Pedersen
2018-12-21 16:21:13 +01:00
parent 43f9df0194
commit 822dc627a1
20 changed files with 633 additions and 74 deletions

View File

@@ -18,7 +18,6 @@ import (
"testing"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/parser/metadecoders"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
@@ -171,34 +170,3 @@ func TestTestRemarshalError(t *testing.T) {
assert.Error(err)
}
func TestRemarshalDetectFormat(t *testing.T) {
t.Parallel()
assert := require.New(t)
for i, test := range []struct {
data string
expect interface{}
}{
{`foo = "bar"`, metadecoders.TOML},
{` foo = "bar"`, metadecoders.TOML},
{`foo="bar"`, metadecoders.TOML},
{`foo: "bar"`, metadecoders.YAML},
{`foo:"bar"`, metadecoders.YAML},
{`{ "foo": "bar"`, metadecoders.JSON},
{`asdfasdf`, false},
{``, false},
} {
errMsg := fmt.Sprintf("[%d] %s", i, test.data)
result, err := detectFormat(test.data)
if b, ok := test.expect.(bool); ok && !b {
assert.Error(err, errMsg)
continue
}
assert.NoError(err, errMsg)
assert.Equal(test.expect, result)
}
}