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

Function TestMappingSlice

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

Source from the content-addressed store, hash-verified

282}
283
284func TestMappingSlice(t *testing.T) {
285 var s struct {
286 Slice []int `form:"slice,default=9"`
287 }
288
289 // default value
290 err := mappingByPtr(&s, formSource{}, "form")
291 require.NoError(t, err)
292 assert.Equal(t, []int{9}, s.Slice)
293
294 // ok
295 err = mappingByPtr(&s, formSource{"slice": {"3", "4"}}, "form")
296 require.NoError(t, err)
297 assert.Equal(t, []int{3, 4}, s.Slice)
298
299 // error
300 err = mappingByPtr(&s, formSource{"slice": {"wrong"}}, "form")
301 require.Error(t, err)
302}
303
304func TestMappingArray(t *testing.T) {
305 var s struct {

Callers

nothing calls this directly

Calls 2

mappingByPtrFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected