(t *testing.T)
| 974 | } |
| 975 | |
| 976 | func TestDecode_DecodeHook(t *testing.T) { |
| 977 | t.Parallel() |
| 978 | |
| 979 | input := map[string]interface{}{ |
| 980 | "vint": "WHAT", |
| 981 | } |
| 982 | |
| 983 | decodeHook := func(from reflect.Kind, to reflect.Kind, v interface{}) (interface{}, error) { |
| 984 | if from == reflect.String && to != reflect.String { |
| 985 | return 5, nil |
| 986 | } |
| 987 | |
| 988 | return v, nil |
| 989 | } |
| 990 | |
| 991 | var result Basic |
| 992 | config := &DecoderConfig{ |
| 993 | DecodeHook: decodeHook, |
| 994 | Result: &result, |
| 995 | } |
| 996 | |
| 997 | decoder, err := NewDecoder(config) |
| 998 | if err != nil { |
| 999 | t.Fatalf("err: %s", err) |
| 1000 | } |
| 1001 | |
| 1002 | err = decoder.Decode(input) |
| 1003 | if err != nil { |
| 1004 | t.Fatalf("got an err: %s", err) |
| 1005 | } |
| 1006 | |
| 1007 | if result.Vint != 5 { |
| 1008 | t.Errorf("vint should be 5: %#v", result.Vint) |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | func TestDecode_DecodeHookType(t *testing.T) { |
| 1013 | t.Parallel() |
nothing calls this directly
no test coverage detected