@@ -518,6 +518,7 @@ func TestStruct(t *testing.T) {
518518 BigEnoughNumberedArray []string
519519 IfaceNonNil interface {}
520520 IfaceInvalid interface {}
521+ TimeMapKey map [time.Time ]string
521522 }
522523
523524 values := url.Values {
@@ -539,6 +540,7 @@ func TestStruct(t *testing.T) {
539540 "TooSmallNumberedArray[2]" : []string {"2" },
540541 "TooSmallCapOKNumberedArray[2]" : []string {"2" },
541542 "BigEnoughNumberedArray[2]" : []string {"1" },
543+ "TimeMapKey[2016-01-02]" : []string {"time" },
542544 }
543545
544546 var test TestStruct
@@ -604,6 +606,12 @@ func TestStruct(t *testing.T) {
604606 Equal (t , test .Time .Equal (tm ), true )
605607 Equal (t , (* test .TimePtr ).Equal (tm ), true )
606608
609+ NotEqual (t , test .TimeMapKey , nil )
610+ Equal (t , len (test .TimeMapKey ), 1 )
611+
612+ _ , ok := test .TimeMapKey [tm ]
613+ Equal (t , ok , true )
614+
607615 s := struct {
608616 Value string
609617 Ignore string `form:"-"`
@@ -655,6 +663,7 @@ func TestErrors(t *testing.T) {
655663 MapBadBoolKey map [bool ]bool
656664 MapBadKeyType map [complex64 ]int
657665 BadArrayValue []int
666+ BadMapKey map [time.Time ]string
658667 }
659668
660669 values := url.Values {
@@ -670,6 +679,7 @@ func TestErrors(t *testing.T) {
670679 "MapBadBoolKey[uh-huh]" : []string {"true" },
671680 "MapBadKeyType[1.4]" : []string {"5" },
672681 "BadArrayValue[0]" : []string {"badintval" },
682+ "BadMapKey[badtime]" : []string {"badtime" },
673683 }
674684
675685 var test TestError
@@ -678,6 +688,7 @@ func TestErrors(t *testing.T) {
678688 decoder .RegisterCustomTypeFunc (func (vals []string ) (interface {}, error ) {
679689 return nil , errors .New ("Bad Type Conversion" )
680690 }, "" )
691+
681692 errs := decoder .Decode (& test , values )
682693 NotEqual (t , errs , nil )
683694
@@ -720,6 +731,29 @@ func TestErrors(t *testing.T) {
720731
721732 k = err ["BadArrayValue[0]" ]
722733 Equal (t , k .Error (), "Invalid Integer Value 'badintval' Type 'int' Namespace 'BadArrayValue[0]'" )
734+
735+ type TestError2 struct {
736+ BadMapKey map [time.Time ]string
737+ }
738+
739+ values2 := url.Values {
740+ "BadMapKey[badtime]" : []string {"badtime" },
741+ }
742+
743+ var test2 TestError2
744+ decoder2 := NewDecoder ()
745+ decoder2 .RegisterCustomTypeFunc (func (vals []string ) (interface {}, error ) {
746+ return time .Parse ("2006-01-02" , vals [0 ])
747+ }, time.Time {})
748+
749+ errs = decoder2 .Decode (& test2 , values2 )
750+ NotEqual (t , errs , nil )
751+
752+ e = errs .Error ()
753+ NotEqual (t , e , "" )
754+
755+ k = err ["BadMapKey" ]
756+ Equal (t , k .Error (), "Unsupported Map Key 'badtime', Type 'time.Time' Namespace 'BadMapKey'" )
723757}
724758
725759func TestPanics (t * testing.T ) {
0 commit comments