@@ -755,34 +755,50 @@ func TestDecodeDatetime(t *testing.T) {
755755}
756756
757757func TestDecodeTextUnmarshaler (t * testing.T ) {
758- type Dict struct {
759- Time time.Time
760- TimeP * time.Time
761- TimeMap map [string ]time.Time
762- }
763-
764- tm := time .Date (1987 , 7 , 5 , 5 , 45 , 0 , 0 , time .UTC )
765- expected := & Dict {
766- Time : tm ,
767- TimeP : & tm ,
768- TimeMap : map [string ]time.Time {"foo" : tm },
758+ tests := []struct {
759+ name string
760+ t interface {}
761+ toml string
762+ want string
763+ }{
764+ {
765+ "time.Time" ,
766+ struct { Time time.Time }{},
767+ "Time = 1987-07-05T05:45:00Z" ,
768+ "map[Time:1987-07-05 05:45:00 +0000 UTC]" ,
769+ },
770+ {
771+ "*time.Time" ,
772+ struct { Time * time.Time }{},
773+ "Time = 1988-07-05T05:45:00Z" ,
774+ "map[Time:1988-07-05 05:45:00 +0000 UTC]" ,
775+ },
776+ {
777+ "map[string]time.Time" ,
778+ struct { Times map [string ]time.Time }{},
779+ "Times.one = 1989-07-05T05:45:00Z\n Times.two = 1990-07-05T05:45:00Z" ,
780+ "map[Times:map[one:1989-07-05 05:45:00 +0000 UTC two:1990-07-05 05:45:00 +0000 UTC]]" ,
781+ },
782+ {
783+ "map[string]*time.Time" ,
784+ struct { Times map [string ]* time.Time }{},
785+ "Times.one = 1989-07-05T05:45:00Z\n Times.two = 1990-07-05T05:45:00Z" ,
786+ "map[Times:map[one:1989-07-05 05:45:00 +0000 UTC two:1990-07-05 05:45:00 +0000 UTC]]" ,
787+ },
769788 }
770789
771- ex1 := `
772- Time = 1987-07-05T05:45:00Z
773- TimeP = 1987-07-05T05:45:00Z
774-
775- [TimeMap]
776- foo = 1987-07-05T05:45:00Z
777- `
790+ for _ , tt := range tests {
791+ t .Run (tt .name , func (t * testing.T ) {
792+ _ , err := Decode (tt .toml , & tt .t )
793+ if err != nil {
794+ t .Fatal (err )
795+ }
778796
779- dict := new (Dict )
780- _ , err := Decode (ex1 , dict )
781- if err != nil {
782- t .Errorf ("Decode error: %v" , err )
783- }
784- if ! reflect .DeepEqual (expected , dict ) {
785- t .Fatalf ("\n %#v\n !=\n %#v\n " , expected , dict )
797+ have := fmt .Sprintf ("%v" , tt .t )
798+ if have != tt .want {
799+ t .Errorf ("\n have: %s\n want: %s" , have , tt .want )
800+ }
801+ })
786802 }
787803}
788804
0 commit comments