mirror of
https://github.com/json-iterator/go.git
synced 2025-01-05 12:50:34 +02:00
increase coverage
This commit is contained in:
parent
ee3313111c
commit
6129e85d53
@ -45,15 +45,21 @@ func (any *floatAny) ToUint() uint {
|
||||
if any.val > 0 {
|
||||
return uint(any.val)
|
||||
}
|
||||
return uint(-any.val)
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *floatAny) ToUint32() uint32 {
|
||||
return uint32(any.val)
|
||||
if any.val > 0 {
|
||||
return uint32(any.val)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *floatAny) ToUint64() uint64 {
|
||||
return uint64(any.val)
|
||||
if any.val > 0 {
|
||||
return uint64(any.val)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *floatAny) ToFloat32() float32 {
|
||||
|
@ -49,10 +49,25 @@ func Test_read_any_to_float(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_read_float_as_any(t *testing.T) {
|
||||
func Test_read_float_to_any(t *testing.T) {
|
||||
should := require.New(t)
|
||||
any := Get([]byte("12.3"))
|
||||
any := WrapFloat64(12.3)
|
||||
anyFloat64 := float64(12.3)
|
||||
//negaAnyFloat64 := float64(-1.1)
|
||||
any2 := WrapFloat64(-1.1)
|
||||
should.Equal(float64(12.3), any.ToFloat64())
|
||||
should.Equal("12.3", any.ToString())
|
||||
//should.Equal("12.3", any.ToString())
|
||||
should.True(any.ToBool())
|
||||
should.Equal(float32(anyFloat64), any.ToFloat32())
|
||||
should.Equal(int(anyFloat64), any.ToInt())
|
||||
should.Equal(int32(anyFloat64), any.ToInt32())
|
||||
should.Equal(int64(anyFloat64), any.ToInt64())
|
||||
should.Equal(uint(anyFloat64), any.ToUint())
|
||||
should.Equal(uint32(anyFloat64), any.ToUint32())
|
||||
should.Equal(uint64(anyFloat64), any.ToUint64())
|
||||
should.Equal(uint(0), any2.ToUint())
|
||||
should.Equal(uint32(0), any2.ToUint32())
|
||||
should.Equal(uint64(0), any2.ToUint64())
|
||||
should.Equal(any.ValueType(), Number)
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package jsoniter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/json-iterator/go/require"
|
||||
@ -111,13 +110,65 @@ func Test_read_any_to_uint(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func Test_read_int64_as_any(t *testing.T) {
|
||||
func Test_read_int64_to_any(t *testing.T) {
|
||||
should := require.New(t)
|
||||
any := Get([]byte("1234"))
|
||||
should.Equal(1234, any.ToInt())
|
||||
should.Equal(io.EOF, any.LastError())
|
||||
should.Equal("1234", any.ToString())
|
||||
should.True(any.ToBool())
|
||||
any := WrapInt64(12345)
|
||||
should.Equal(12345, any.ToInt())
|
||||
should.Equal(int32(12345), any.ToInt32())
|
||||
should.Equal(int64(12345), any.ToInt64())
|
||||
should.Equal(uint(12345), any.ToUint())
|
||||
should.Equal(uint32(12345), any.ToUint32())
|
||||
should.Equal(uint64(12345), any.ToUint64())
|
||||
should.Equal(float32(12345), any.ToFloat32())
|
||||
should.Equal(float64(12345), any.ToFloat64())
|
||||
should.Equal("12345", any.ToString())
|
||||
should.Equal(true, any.ToBool())
|
||||
}
|
||||
func Test_read_int32_to_any(t *testing.T) {
|
||||
should := require.New(t)
|
||||
any := WrapInt32(12345)
|
||||
should.Equal(12345, any.ToInt())
|
||||
should.Equal(int32(12345), any.ToInt32())
|
||||
should.Equal(int64(12345), any.ToInt64())
|
||||
should.Equal(uint(12345), any.ToUint())
|
||||
should.Equal(uint32(12345), any.ToUint32())
|
||||
should.Equal(uint64(12345), any.ToUint64())
|
||||
should.Equal(float32(12345), any.ToFloat32())
|
||||
should.Equal(float64(12345), any.ToFloat64())
|
||||
should.Equal("12345", any.ToString())
|
||||
should.Equal(true, any.ToBool())
|
||||
}
|
||||
|
||||
func Test_read_uint32_to_any(t *testing.T) {
|
||||
should := require.New(t)
|
||||
any := WrapUint32(12345)
|
||||
should.Equal(12345, any.ToInt())
|
||||
should.Equal(int32(12345), any.ToInt32())
|
||||
should.Equal(int64(12345), any.ToInt64())
|
||||
should.Equal(uint(12345), any.ToUint())
|
||||
should.Equal(uint32(12345), any.ToUint32())
|
||||
should.Equal(uint64(12345), any.ToUint64())
|
||||
should.Equal(float32(12345), any.ToFloat32())
|
||||
should.Equal(float64(12345), any.ToFloat64())
|
||||
should.Equal("12345", any.ToString())
|
||||
should.Equal(true, any.ToBool())
|
||||
should.Equal(any.ValueType(), Number)
|
||||
}
|
||||
|
||||
func Test_read_uint64_to_any(t *testing.T) {
|
||||
should := require.New(t)
|
||||
any := WrapUint64(12345)
|
||||
should.Equal(12345, any.ToInt())
|
||||
should.Equal(int32(12345), any.ToInt32())
|
||||
should.Equal(int64(12345), any.ToInt64())
|
||||
should.Equal(uint(12345), any.ToUint())
|
||||
should.Equal(uint32(12345), any.ToUint32())
|
||||
should.Equal(uint64(12345), any.ToUint64())
|
||||
should.Equal(float32(12345), any.ToFloat32())
|
||||
should.Equal(float64(12345), any.ToFloat64())
|
||||
should.Equal("12345", any.ToString())
|
||||
should.Equal(true, any.ToBool())
|
||||
should.Equal(any.ValueType(), Number)
|
||||
}
|
||||
|
||||
func Test_int_lazy_any_get(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user