@@ -430,38 +430,56 @@ func TestDecodeSizedInts(t *testing.T) {
430
430
431
431
type NopUnmarshalTOML int
432
432
433
- func (NopUnmarshalTOML ) UnmarshalTOML (p interface {}) error { return nil }
433
+ func (n * NopUnmarshalTOML ) UnmarshalTOML (p interface {}) error {
434
+ * n = 42
435
+ return nil
436
+ }
434
437
435
438
func TestDecodeTypes (t * testing.T ) {
436
- type mystr string
439
+ type (
440
+ mystr string
441
+ myiface interface {}
442
+ )
437
443
438
444
for _ , tt := range []struct {
439
- v interface {}
440
- want string
445
+ v interface {}
446
+ want string
447
+ wantErr string
441
448
}{
442
- {new (map [string ]bool ), "" },
443
- {new (map [mystr ]bool ), "" },
444
- {new (NopUnmarshalTOML ), "" },
449
+ {new (map [string ]bool ), "&map[F:true]" , "" },
450
+ {new (map [mystr ]bool ), "&map[F:true]" , "" },
451
+ {new (NopUnmarshalTOML ), "42" , "" },
452
+ {new (map [interface {}]bool ), "&map[F:true]" , "" },
453
+ {new (map [myiface ]bool ), "&map[F:true]" , "" },
445
454
446
- {3 , `toml: cannot decode to non-pointer "int"` },
447
- {map [string ]interface {}{}, `toml: cannot decode to non-pointer "map[string]interface {}"` },
455
+ {3 , "" , `toml: cannot decode to non-pointer "int"` },
456
+ {map [string ]interface {}{}, "" , `toml: cannot decode to non-pointer "map[string]interface {}"` },
448
457
449
- {(* int )(nil ), `toml: cannot decode to nil value of "*int"` },
450
- {(* Unmarshaler )(nil ), `toml: cannot decode to nil value of "*toml.Unmarshaler"` },
451
- {nil , `toml: cannot decode to non-pointer <nil>` },
458
+ {(* int )(nil ), "" , `toml: cannot decode to nil value of "*int"` },
459
+ {(* Unmarshaler )(nil ), "" , `toml: cannot decode to nil value of "*toml.Unmarshaler"` },
460
+ {nil , "" , `toml: cannot decode to non-pointer <nil>` },
452
461
453
- {new (map [int ]string ), "toml: cannot decode to a map with non-string key type" },
454
- {new (map [interface {}]string ), "toml: cannot decode to a map with non-string key type" },
462
+ {new (map [int ]string ), "" , "toml: cannot decode to a map with non-string key type" },
455
463
456
- {new (struct { F int }), `toml: line 1 (last key "F"): incompatible types: TOML value has type bool; destination has type integer` },
457
- {new (map [string ]int ), `toml: line 1 (last key "F"): incompatible types: TOML value has type bool; destination has type integer` },
458
- {new (int ), `toml: cannot decode to type int` },
459
- {new ([]int ), "toml: cannot decode to type []int" },
464
+ {new (struct { F int }), "" , `toml: line 1 (last key "F"): incompatible types: TOML value has type bool; destination has type integer` },
465
+ {new (map [string ]int ), "" , `toml: line 1 (last key "F"): incompatible types: TOML value has type bool; destination has type integer` },
466
+ {new (int ), "" , `toml: cannot decode to type int` },
467
+ {new ([]int ), "" , " toml: cannot decode to type []int" },
460
468
} {
461
469
t .Run (fmt .Sprintf ("%T" , tt .v ), func (t * testing.T ) {
462
470
_ , err := Decode (`F = true` , tt .v )
463
- if ! errorContains (err , tt .want ) {
464
- t .Errorf ("wrong error\n have: %q\n want: %q" , err , tt .want )
471
+ if ! errorContains (err , tt .wantErr ) {
472
+ t .Fatalf ("wrong error\n have: %q\n want: %q" , err , tt .wantErr )
473
+ }
474
+
475
+ if err == nil {
476
+ have := fmt .Sprintf ("%v" , tt .v )
477
+ if n , ok := tt .v .(* NopUnmarshalTOML ); ok {
478
+ have = fmt .Sprintf ("%v" , * n )
479
+ }
480
+ if have != tt .want {
481
+ t .Errorf ("\n have: %s\n want: %s" , have , tt .want )
482
+ }
465
483
}
466
484
})
467
485
}
0 commit comments