Support literal multiline marshal (#485)

Use struct tag `multiline:"true" literal:"true"` to enable it.
This commit is contained in:
Thomas Pelletier
2021-03-25 20:57:38 -04:00
committed by GitHub
parent b59c12a70d
commit ce6fbd7bc0
4 changed files with 46 additions and 1 deletions
+26
View File
@@ -1294,6 +1294,32 @@ NonCommented = "Not commented line"
}
}
func TestMarshalMultilineLiteral(t *testing.T) {
type Doc struct {
Value string `multiline:"true" literal:"true"`
}
d := Doc{
Value: "hello\nworld\ttest\nend",
}
expected := []byte(`Value = '''
hello
world test
end
'''
`)
b, err := Marshal(d)
if err != nil {
t.Fatal("unexpected error")
}
if !bytes.Equal(b, expected) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, b)
}
}
func TestMarshalNonPrimitiveTypeCommented(t *testing.T) {
expectedToml := []byte(`
# [CommentedMapField]