Skip to content
Snippets Groups Projects
Commit 58a182ee authored by ko_oler's avatar ko_oler
Browse files

правки по ПР: добавлена проверка для int64

parent 4845bf4a
No related branches found
No related tags found
No related merge requests found
......@@ -88,6 +88,9 @@ func (NumberType) decode(_ context.Context, field *Field, v interface{}) (interf
case NumberFormatInt:
switch i := n.(type) {
case int64:
if i > maxInt || i < minInt {
return nil, errors.New("integer out of range")
}
return i, nil
case uint64:
if i > maxInt {
......
......@@ -15,20 +15,20 @@ func TestNumberField_Decode(t *testing.T) {
want interface{}
wantErr bool
}{
{"Correct", Number("int"), int64(2), int64(2), false}, // #0
{"Correct", Number("int"), 2.2, int64(2), false}, // #1
{"Correct", Number("int"), 2, int64(2), false}, // #2
{"Correct", Number("int"), float32(2.2), int64(2), false}, // #3
{"Correct", Number("int"), float64(2.6), int64(3), false}, // #4
{"Correct", Number("int"), 2.6, int64(3), false}, // #5
{"MaxInt64", Number(NumberFormatInt), int64(math.MaxInt64), int64(math.MaxInt64), false}, // #6
{"MinInt64", Number(NumberFormatInt), int64(math.MinInt64), int64(math.MinInt64), false}, // #7
{"maxInt in float", Number(NumberFormatInt), float64(maxInt), int64(maxInt), false}, // #8
{"minInt in float", Number(NumberFormatInt), float64(minInt), int64(minInt), false}, // #9
{"Convert error", Number(NumberFormatInt), math.MaxFloat64, nil, true}, // #10
{"Convert error", Number(NumberFormatInt), -math.MaxFloat64, nil, true}, // #11
{"Convert error", Number(NumberFormatInt), float64(math.MaxInt64), nil, true}, // #13
{"Convert error", Number(NumberFormatInt), float64(math.MinInt64), nil, true}, // #14
{"Correct", Number("int"), int64(2), int64(2), false}, // #0
{"Correct", Number("int"), 2.2, int64(2), false}, // #1
{"Correct", Number("int"), 2, int64(2), false}, // #2
{"Correct", Number("int"), float32(2.2), int64(2), false}, // #3
{"Correct", Number("int"), float64(2.6), int64(3), false}, // #4
{"Correct", Number("int"), 2.6, int64(3), false}, // #5
{"MaxInt64", Number(NumberFormatInt), int64(math.MaxInt64), nil, true}, // #6
{"MinInt64", Number(NumberFormatInt), int64(math.MinInt64), nil, true}, // #7
{"maxInt in float", Number(NumberFormatInt), float64(maxInt), int64(maxInt), false}, // #8
{"minInt in float", Number(NumberFormatInt), float64(minInt), int64(minInt), false}, // #9
{"Convert error", Number(NumberFormatInt), math.MaxFloat64, nil, true}, // #10
{"Convert error", Number(NumberFormatInt), -math.MaxFloat64, nil, true}, // #11
{"Convert error", Number(NumberFormatInt), float64(math.MaxInt64), nil, true}, // #13
{"Convert error", Number(NumberFormatInt), float64(math.MinInt64), nil, true}, // #14
{"Correct", Number("float"), int8(2), 2.0, false}, // #15
{"Correct", Number("float"), 2.2, 2.2, false}, // #16
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment