MCPcopy
hub / github.com/gin-gonic/gin / TestMappingArray

Function TestMappingArray

binding/form_mapping_test.go:304–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

302}
303
304func TestMappingArray(t *testing.T) {
305 var s struct {
306 Array [2]int `form:"array,default=9"`
307 }
308
309 // wrong default
310 err := mappingByPtr(&s, formSource{}, "form")
311 require.Error(t, err)
312
313 // ok
314 err = mappingByPtr(&s, formSource{"array": {"3", "4"}}, "form")
315 require.NoError(t, err)
316 assert.Equal(t, [2]int{3, 4}, s.Array)
317
318 // error - not enough vals
319 err = mappingByPtr(&s, formSource{"array": {"3"}}, "form")
320 require.Error(t, err)
321
322 // error - wrong value
323 err = mappingByPtr(&s, formSource{"array": {"wrong"}}, "form")
324 require.Error(t, err)
325}
326
327func TestMappingCollectionFormat(t *testing.T) {
328 var s struct {

Callers

nothing calls this directly

Calls 2

mappingByPtrFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected