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

Function Test_decoderBuilder

binder/mapping_test.go:399–427  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

397}
398
399func Test_decoderBuilder(t *testing.T) {
400 t.Parallel()
401 type customInt int
402 conv := func(s string) reflect.Value {
403 i, err := strconv.Atoi(s)
404 if err != nil {
405 panic(err)
406 }
407 return reflect.ValueOf(customInt(i))
408 }
409 parserConfig := ParserConfig{
410 SetAliasTag: "custom",
411 ParserType: []ParserType{{
412 CustomType: customInt(0),
413 Converter: conv,
414 }},
415 IgnoreUnknownKeys: false,
416 ZeroEmpty: false,
417 }
418 decAny := decoderBuilder(bindingForm, parserConfig)
419 dec, ok := decAny.(*schema.Decoder)
420 require.True(t, ok)
421 var out struct {
422 X customInt `custom:"x"`
423 }
424 err := dec.Decode(&out, map[string][]string{"x": {"7"}})
425 require.NoError(t, err)
426 require.Equal(t, customInt(7), out.X)
427}
428
429func Test_parseToMap_Extended(t *testing.T) {
430 t.Parallel()

Callers

nothing calls this directly

Calls 2

customIntTypeAlias · 0.85
decoderBuilderFunction · 0.85

Tested by

no test coverage detected