(t *testing.T)
| 1101 | } |
| 1102 | |
| 1103 | func TestDecode_NilPointerHook(t *testing.T) { |
| 1104 | t.Parallel() |
| 1105 | |
| 1106 | input := map[string]interface{}{ |
| 1107 | "value": "", |
| 1108 | } |
| 1109 | |
| 1110 | decodeHook := func(f, t reflect.Type, v interface{}) (interface{}, error) { |
| 1111 | if typed, ok := v.(string); ok { |
| 1112 | if typed == "" { |
| 1113 | return nil, nil |
| 1114 | } |
| 1115 | } |
| 1116 | return v, nil |
| 1117 | } |
| 1118 | |
| 1119 | var result NilPointer |
| 1120 | config := &DecoderConfig{ |
| 1121 | DecodeHook: decodeHook, |
| 1122 | Result: &result, |
| 1123 | } |
| 1124 | |
| 1125 | decoder, err := NewDecoder(config) |
| 1126 | if err != nil { |
| 1127 | t.Fatalf("err: %s", err) |
| 1128 | } |
| 1129 | |
| 1130 | err = decoder.Decode(input) |
| 1131 | if err != nil { |
| 1132 | t.Fatalf("got an err: %s", err) |
| 1133 | } |
| 1134 | |
| 1135 | if result.Value != nil { |
| 1136 | t.Errorf("W should be nil: %#v", result.Value) |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | func TestDecode_FuncHook(t *testing.T) { |
| 1141 | t.Parallel() |
nothing calls this directly
no test coverage detected