mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
d6c8cd7718
commit
9bba9a3a98
2 changed files with 82 additions and 82 deletions
|
@ -46,7 +46,9 @@ func InterfaceToConfig(in interface{}, format metadecoders.Format, w io.Writer)
|
|||
return err
|
||||
|
||||
case metadecoders.TOML:
|
||||
return toml.NewEncoder(w).Encode(in)
|
||||
enc := toml.NewEncoder(w)
|
||||
enc.SetIndentTables(true)
|
||||
return enc.Encode(in)
|
||||
case metadecoders.JSON:
|
||||
b, err := json.MarshalIndent(in, "", " ")
|
||||
if err != nil {
|
||||
|
|
|
@ -30,6 +30,8 @@ func TestRemarshal(t *testing.T) {
|
|||
ns := New(newDeps(v))
|
||||
c := qt.New(t)
|
||||
|
||||
c.Run("Roundtrip variants", func(c *qt.C) {
|
||||
|
||||
tomlExample := `title = 'Test Metadata'
|
||||
|
||||
[[resources]]
|
||||
|
@ -107,17 +109,10 @@ title: Test Metadata
|
|||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemarshalComments(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
v := config.New()
|
||||
v.Set("contentDir", "content")
|
||||
ns := New(newDeps(v))
|
||||
|
||||
c := qt.New(t)
|
||||
})
|
||||
|
||||
c.Run("Comments", func(c *qt.C) {
|
||||
input := `
|
||||
Hugo = "Rules"
|
||||
|
||||
|
@ -150,30 +145,24 @@ a = 'b'
|
|||
t.Fatalf("[%s] Expected \n%v\ngot\n>>%v\ndiff:\n%v\n", fromTo, expected, converted, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
func TestTestRemarshalError(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := qt.New(t)
|
||||
// Issue 8850
|
||||
c.Run("TOML Indent", func(c *qt.C) {
|
||||
input := `
|
||||
|
||||
v := config.New()
|
||||
v.Set("contentDir", "content")
|
||||
ns := New(newDeps(v))
|
||||
[params]
|
||||
[params.variables]
|
||||
a = "b"
|
||||
|
||||
_, err := ns.Remarshal("asdf", "asdf")
|
||||
c.Assert(err, qt.Not(qt.IsNil))
|
||||
`
|
||||
|
||||
_, err = ns.Remarshal("json", "asdf")
|
||||
c.Assert(err, qt.Not(qt.IsNil))
|
||||
}
|
||||
|
||||
func TestTestRemarshalMapInput(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := qt.New(t)
|
||||
v := config.New()
|
||||
v.Set("contentDir", "content")
|
||||
ns := New(newDeps(v))
|
||||
converted, err := ns.Remarshal("toml", input)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(converted, qt.Equals, "[params]\n [params.variables]\n a = 'b'\n\n\n")
|
||||
})
|
||||
|
||||
c.Run("Map input", func(c *qt.C) {
|
||||
input := map[string]interface{}{
|
||||
"hello": "world",
|
||||
}
|
||||
|
@ -181,4 +170,13 @@ func TestTestRemarshalMapInput(t *testing.T) {
|
|||
output, err := ns.Remarshal("toml", input)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(output, qt.Equals, "hello = 'world'\n")
|
||||
})
|
||||
|
||||
c.Run("Error", func(c *qt.C) {
|
||||
_, err := ns.Remarshal("asdf", "asdf")
|
||||
c.Assert(err, qt.Not(qt.IsNil))
|
||||
|
||||
_, err = ns.Remarshal("json", "asdf")
|
||||
c.Assert(err, qt.Not(qt.IsNil))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue