diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-03-20 18:23:32 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-03-20 18:23:32 +0100 |
commit | 61f6e9f63b0d2c8d7c3a2a88a3d2885c9a7d8165 (patch) | |
tree | c79dc587b1b99fd4ff48ab2d7a146a01826310d5 | |
parent | 904a3d9ddf523d452d04d0b5814503e0ff17bd2e (diff) |
tpl/transform: Add a comments test for Remarshal
See #4521
-rw-r--r-- | tpl/transform/remarshal_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tpl/transform/remarshal_test.go b/tpl/transform/remarshal_test.go index 78980e62c..5e3ed8b34 100644 --- a/tpl/transform/remarshal_test.go +++ b/tpl/transform/remarshal_test.go @@ -108,6 +108,48 @@ title: Test Metadata } +func TestRemarshalComments(t *testing.T) { + t.Parallel() + + ns := New(newDeps(viper.New())) + assert := require.New(t) + + input := ` +Hugo = "Rules" + +# It really does! + +[m] +# A comment +a = "b" + +` + + expected := ` +Hugo = "Rules" + +[m] + a = "b" +` + + for _, format := range []string{"json", "yaml", "toml"} { + fromTo := fmt.Sprintf("%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) + assert.NoError(err, fromTo) + } + + diff := helpers.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() |