Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-08-04 12:33:30 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-08-04 12:39:16 +0300
commit9bba9a3a98fa268391597d8d7a52112fb401d952 (patch)
tree3995a81a85377b20da92aa33b9d1a536699311c9 /tpl/transform
parentd6c8cd771834ae2913658c652e30a9feadc2a7b7 (diff)
parser: Indent TOML tables
Fixes #8850
Diffstat (limited to 'tpl/transform')
-rw-r--r--tpl/transform/remarshal_test.go146
1 files changed, 72 insertions, 74 deletions
diff --git a/tpl/transform/remarshal_test.go b/tpl/transform/remarshal_test.go
index c34122a2a..2cb4c3a2f 100644
--- a/tpl/transform/remarshal_test.go
+++ b/tpl/transform/remarshal_test.go
@@ -30,7 +30,9 @@ func TestRemarshal(t *testing.T) {
ns := New(newDeps(v))
c := qt.New(t)
- tomlExample := `title = 'Test Metadata'
+ c.Run("Roundtrip variants", func(c *qt.C) {
+
+ tomlExample := `title = 'Test Metadata'
[[resources]]
src = '**image-4.png'
@@ -46,7 +48,7 @@ func TestRemarshal(t *testing.T) {
byline = 'bep'
`
- yamlExample := `resources:
+ yamlExample := `resources:
- params:
byline: picasso
src: '**image-4.png'
@@ -59,7 +61,7 @@ func TestRemarshal(t *testing.T) {
title: Test Metadata
`
- jsonExample := `{
+ jsonExample := `{
"resources": [
{
"params": {
@@ -81,44 +83,37 @@ title: Test Metadata
}
`
- variants := []struct {
- format string
- data string
- }{
- {"yaml", yamlExample},
- {"json", jsonExample},
- {"toml", tomlExample},
- {"TOML", tomlExample},
- {"Toml", tomlExample},
- {" TOML ", tomlExample},
- }
-
- for _, v1 := range variants {
- for _, v2 := range variants {
- // Both from and to may be the same here, but that is fine.
- fromTo := qt.Commentf("%s => %s", v2.format, v1.format)
-
- converted, err := ns.Remarshal(v1.format, v2.data)
- c.Assert(err, qt.IsNil, fromTo)
- diff := htesting.DiffStrings(v1.data, converted)
- if len(diff) > 0 {
- t.Errorf("[%s] Expected \n%v\ngot\n%v\ndiff:\n%v", fromTo, v1.data, converted, diff)
- }
-
+ variants := []struct {
+ format string
+ data string
+ }{
+ {"yaml", yamlExample},
+ {"json", jsonExample},
+ {"toml", tomlExample},
+ {"TOML", tomlExample},
+ {"Toml", tomlExample},
+ {" TOML ", tomlExample},
}
- }
-}
-func TestRemarshalComments(t *testing.T) {
- t.Parallel()
+ for _, v1 := range variants {
+ for _, v2 := range variants {
+ // Both from and to may be the same here, but that is fine.
+ fromTo := qt.Commentf("%s => %s", v2.format, v1.format)
- v := config.New()
- v.Set("contentDir", "content")
- ns := New(newDeps(v))
+ converted, err := ns.Remarshal(v1.format, v2.data)
+ c.Assert(err, qt.IsNil, fromTo)
+ diff := htesting.DiffStrings(v1.data, converted)
+ if len(diff) > 0 {
+ t.Errorf("[%s] Expected \n%v\ngot\n%v\ndiff:\n%v", fromTo, v1.data, converted, diff)
+ }
- c := qt.New(t)
+ }
+ }
+
+ })
- input := `
+ c.Run("Comments", func(c *qt.C) {
+ input := `
Hugo = "Rules"
# It really does!
@@ -129,56 +124,59 @@ a = "b"
`
- expected := `Hugo = 'Rules'
+ expected := `Hugo = 'Rules'
[m]
a = 'b'
`
- for _, format := range []string{"json", "yaml", "toml"} {
- fromTo := qt.Commentf("%s => %s", "toml", format)
+ for _, format := range []string{"json", "yaml", "toml"} {
+ fromTo := qt.Commentf("%s => %s", "toml", format)
- converted := input
- var err error
- // Do a round-trip conversion
- for _, toFormat := range []string{format, "toml"} {
- converted, err = ns.Remarshal(toFormat, converted)
- c.Assert(err, qt.IsNil, fromTo)
- }
+ converted := input
+ var err error
+ // Do a round-trip conversion
+ for _, toFormat := range []string{format, "toml"} {
+ converted, err = ns.Remarshal(toFormat, converted)
+ c.Assert(err, qt.IsNil, fromTo)
+ }
- diff := htesting.DiffStrings(expected, converted)
- if len(diff) > 0 {
- t.Fatalf("[%s] Expected \n%v\ngot\n>>%v\ndiff:\n%v\n", fromTo, expected, converted, diff)
+ diff := htesting.DiffStrings(expected, converted)
+ if len(diff) > 0 {
+ 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))
+ 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")
+ })
- _, err = ns.Remarshal("json", "asdf")
- c.Assert(err, qt.Not(qt.IsNil))
-}
+ c.Run("Map input", func(c *qt.C) {
+ input := map[string]interface{}{
+ "hello": "world",
+ }
-func TestTestRemarshalMapInput(t *testing.T) {
- t.Parallel()
- c := qt.New(t)
- v := config.New()
- v.Set("contentDir", "content")
- ns := New(newDeps(v))
+ output, err := ns.Remarshal("toml", input)
+ c.Assert(err, qt.IsNil)
+ c.Assert(output, qt.Equals, "hello = 'world'\n")
+ })
- input := map[string]interface{}{
- "hello": "world",
- }
+ c.Run("Error", func(c *qt.C) {
+ _, err := ns.Remarshal("asdf", "asdf")
+ c.Assert(err, qt.Not(qt.IsNil))
- output, err := ns.Remarshal("toml", input)
- c.Assert(err, qt.IsNil)
- c.Assert(output, qt.Equals, "hello = 'world'\n")
+ _, err = ns.Remarshal("json", "asdf")
+ c.Assert(err, qt.Not(qt.IsNil))
+ })
}