MCPcopy
hub / github.com/gofiber/fiber / Test_SetParserDecoder_CustomConverter

Function Test_SetParserDecoder_CustomConverter

binder/binder_test.go:126–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func Test_SetParserDecoder_CustomConverter(t *testing.T) {
127 type myInt int
128 conv := func(s string) reflect.Value {
129 v, _ := strconv.Atoi(s) //nolint:errcheck // not needed
130 mi := myInt(v)
131 return reflect.ValueOf(mi)
132 }
133
134 SetParserDecoder(ParserConfig{ParserType: []ParserType{{CustomType: myInt(0), Converter: conv}}})
135 defer SetParserDecoder(ParserConfig{IgnoreUnknownKeys: true, ZeroEmpty: true})
136
137 type data struct {
138 V myInt `query:"v"`
139 }
140 d := new(data)
141 err := parse("query", d, map[string][]string{"v": {"5"}})
142 require.NoError(t, err)
143 require.Equal(t, myInt(5), d.V)
144}
145
146// Test_SetParserDecoder_AliasTagIgnored: ParserConfig.SetAliasTag must not
147// override the per-source binding tag (one global tag breaks multi-source binding).

Callers

nothing calls this directly

Calls 3

myIntTypeAlias · 0.85
SetParserDecoderFunction · 0.85
parseFunction · 0.85

Tested by

no test coverage detected