@@ -1261,6 +1261,43 @@ c = 3
1261
1261
}
1262
1262
}
1263
1263
1264
+ type (
1265
+ Doc1 struct { N string }
1266
+ Doc2 struct { N string }
1267
+ )
1268
+
1269
+ func (d Doc1 ) MarshalTOML () ([]byte , error ) { return []byte (`marshal_toml = "` + d .N + `"` ), nil }
1270
+ func (d Doc2 ) MarshalText () ([]byte , error ) { return []byte (`marshal_text = "` + d .N + `"` ), nil }
1271
+
1272
+ // MarshalTOML and MarshalText on the top level type, rather than a field.
1273
+ func TestMarshalDoc (t * testing.T ) {
1274
+ t .Run ("toml" , func (t * testing.T ) {
1275
+ var buf bytes.Buffer
1276
+ err := NewEncoder (& buf ).Encode (Doc1 {"asd" })
1277
+ if err != nil {
1278
+ t .Fatal (err )
1279
+ }
1280
+
1281
+ want := `marshal_toml = "asd"`
1282
+ if want != buf .String () {
1283
+ t .Errorf ("\n have: %s\n want: %s\n " , buf .String (), want )
1284
+ }
1285
+ })
1286
+
1287
+ t .Run ("text" , func (t * testing.T ) {
1288
+ var buf bytes.Buffer
1289
+ err := NewEncoder (& buf ).Encode (Doc2 {"asd" })
1290
+ if err != nil {
1291
+ t .Fatal (err )
1292
+ }
1293
+
1294
+ want := `"marshal_text = \"asd\""`
1295
+ if want != buf .String () {
1296
+ t .Errorf ("\n have: %s\n want: %s\n " , buf .String (), want )
1297
+ }
1298
+ })
1299
+ }
1300
+
1264
1301
func encodeExpected (t * testing.T , label string , val interface {}, want string , wantErr error ) {
1265
1302
t .Helper ()
1266
1303
t .Run (label , func (t * testing.T ) {
0 commit comments