@@ -1048,6 +1048,51 @@ func TestIssue786(t *testing.T) {
1048
1048
require .NoError (t , err )
1049
1049
1050
1050
require .Equal (t , "" , string (b ))
1051
+
1052
+ type General struct {
1053
+ From string `toml:"from,omitempty" json:"from,omitempty" comment:"from in graphite-web format, the local TZ is used"`
1054
+ Randomize bool `toml:"randomize" json:"randomize" comment:"randomize starting time with [0,step)"`
1055
+ }
1056
+
1057
+ type Custom struct {
1058
+ Name string `toml:"name" json:"name,omitempty" comment:"names for generator, braces are expanded like in shell"`
1059
+ Type string `toml:"type,omitempty" json:"type,omitempty" comment:"type of generator"`
1060
+ General
1061
+ }
1062
+ type Config struct {
1063
+ General
1064
+ Custom []Custom `toml:"custom,omitempty" json:"custom,omitempty" comment:"generators with custom parameters can be specified separately"`
1065
+ }
1066
+
1067
+ buf := new (bytes.Buffer )
1068
+ config := & Config {General : General {From : "-2d" , Randomize : true }}
1069
+ config .Custom = []Custom {{Name : "omit" , General : General {Randomize : false }}}
1070
+ config .Custom = append (config .Custom , Custom {Name : "present" , General : General {From : "-2d" , Randomize : true }})
1071
+ encoder := toml .NewEncoder (buf )
1072
+ encoder .Encode (config )
1073
+
1074
+ expected := `# from in graphite-web format, the local TZ is used
1075
+ from = '-2d'
1076
+ # randomize starting time with [0,step)
1077
+ randomize = true
1078
+
1079
+ # generators with custom parameters can be specified separately
1080
+ [[custom]]
1081
+ # names for generator, braces are expanded like in shell
1082
+ name = 'omit'
1083
+ # randomize starting time with [0,step)
1084
+ randomize = false
1085
+
1086
+ [[custom]]
1087
+ # names for generator, braces are expanded like in shell
1088
+ name = 'present'
1089
+ # from in graphite-web format, the local TZ is used
1090
+ from = '-2d'
1091
+ # randomize starting time with [0,step)
1092
+ randomize = true
1093
+ `
1094
+
1095
+ require .Equal (t , expected , buf .String ())
1051
1096
}
1052
1097
1053
1098
func TestMarshalNestedAnonymousStructs (t * testing.T ) {
0 commit comments