@@ -448,6 +448,63 @@ func TestStringToSliceHookFunc(t *testing.T) {
448448 })
449449}
450450
451+ func TestStringToWeakSliceHookFunc (t * testing.T ) {
452+ f := StringToWeakSliceHookFunc ("," )
453+
454+ strValue := reflect .ValueOf ("42" )
455+ sliceValue := reflect .ValueOf ([]string {"42" })
456+ sliceValue2 := reflect .ValueOf ([]byte ("42" ))
457+
458+ cases := []struct {
459+ f , t reflect.Value
460+ result any
461+ err bool
462+ }{
463+ {sliceValue , sliceValue , []string {"42" }, false },
464+ {sliceValue2 , sliceValue2 , []byte ("42" ), false },
465+ {reflect .ValueOf ([]byte ("42" )), reflect .ValueOf ([]byte {}), []byte ("42" ), false },
466+ {strValue , strValue , "42" , false },
467+ {
468+ reflect .ValueOf ("foo,bar,baz" ),
469+ sliceValue ,
470+ []string {"foo" , "bar" , "baz" },
471+ false ,
472+ },
473+ {
474+ reflect .ValueOf ("foo,bar,baz" ),
475+ sliceValue2 ,
476+ []string {"foo" , "bar" , "baz" },
477+ false ,
478+ },
479+ {
480+ reflect .ValueOf ("" ),
481+ sliceValue ,
482+ []string {},
483+ false ,
484+ },
485+ {
486+ reflect .ValueOf ("" ),
487+ sliceValue2 ,
488+ []string {},
489+ false ,
490+ },
491+ }
492+
493+ for i , tc := range cases {
494+ actual , err := DecodeHookExec (f , tc .f , tc .t )
495+
496+ if tc .err != (err != nil ) {
497+ t .Fatalf ("case %d: expected err %#v" , i , tc .err )
498+ }
499+
500+ if ! reflect .DeepEqual (actual , tc .result ) {
501+ t .Fatalf (
502+ "case %d: expected %#v, got %#v" ,
503+ i , tc .result , actual )
504+ }
505+ }
506+ }
507+
451508func TestStringToTimeDurationHookFunc (t * testing.T ) {
452509 suite := decodeHookTestSuite [string , time.Duration ]{
453510 fn : StringToTimeDurationHookFunc (),
0 commit comments