Comment annotation for Marshal (#185)
This commit is contained in:
committed by
Thomas Pelletier
parent
16398bac15
commit
690dbc9ee7
@@ -598,3 +598,54 @@ func TestNestedCustomMarshaler(t *testing.T) {
|
||||
t.Errorf("Bad nested custom marshaler: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
var commentTestToml = []byte(`
|
||||
# it's a comment on type
|
||||
[postgres]
|
||||
# isCommented = "dvalue"
|
||||
noComment = "cvalue"
|
||||
|
||||
# A comment on AttrB with a
|
||||
# break line
|
||||
password = "bvalue"
|
||||
|
||||
# A comment on AttrA
|
||||
user = "avalue"
|
||||
|
||||
[[postgres.My]]
|
||||
|
||||
# a comment on my on typeC
|
||||
My = "Foo"
|
||||
|
||||
[[postgres.My]]
|
||||
|
||||
# a comment on my on typeC
|
||||
My = "Baar"
|
||||
`)
|
||||
|
||||
func TestMarshalComment(t *testing.T) {
|
||||
type TypeC struct {
|
||||
My string `comment:"a comment on my on typeC"`
|
||||
}
|
||||
type TypeB struct {
|
||||
AttrA string `toml:"user" comment:"A comment on AttrA"`
|
||||
AttrB string `toml:"password" comment:"A comment on AttrB with a\n break line"`
|
||||
AttrC string `toml:"noComment"`
|
||||
AttrD string `toml:"isCommented" commented:"true"`
|
||||
My []TypeC
|
||||
}
|
||||
type TypeA struct {
|
||||
TypeB TypeB `toml:"postgres" comment:"it's a comment on type"`
|
||||
}
|
||||
|
||||
ta := []TypeC{{My: "Foo"}, {My: "Baar"}}
|
||||
config := TypeA{TypeB{AttrA: "avalue", AttrB: "bvalue", AttrC: "cvalue", AttrD: "dvalue", My: ta}}
|
||||
result, err := Marshal(config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := commentTestToml
|
||||
if !bytes.Equal(result, expected) {
|
||||
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user