improve: number range compare left and righ value (#2315)

Co-authored-by: wanglonghui7 <wanglonghui7@jd.com>
master
lowang-bh 2 years ago committed by GitHub
parent 813625d995
commit 1b477bbef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -261,6 +261,26 @@ func TestMarshal_RangeOut(t *testing.T) {
}
}
func TestMarshal_RangeIllegal(t *testing.T) {
tests := []interface{}{
struct {
Int int `json:"int,range=[3:1]"`
}{
Int: 2,
},
struct {
Int int `json:"int,range=(3:1]"`
}{
Int: 2,
},
}
for _, test := range tests {
_, err := Marshal(test)
assert.Equal(t, err, errNumberRange)
}
}
func TestMarshal_FromString(t *testing.T) {
v := struct {
Age int `json:"age,string"`

@ -311,6 +311,10 @@ func parseNumberRange(str string) (*numberRange, error) {
right = math.MaxFloat64
}
if left >= right {
return nil, errNumberRange
}
return &numberRange{
left: left,
leftInclude: leftInclude,

Loading…
Cancel
Save