mirror of
https://github.com/json-iterator/go.git
synced 2024-11-24 08:22:14 +02:00
merge
This commit is contained in:
commit
dfa4bdf888
@ -1,89 +1,247 @@
|
||||
package extra
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterFuzzyDecoders()
|
||||
}
|
||||
|
||||
func Test_string_to_string(t *testing.T) {
|
||||
func Test_any_to_string(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val string
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal("100", val)
|
||||
should.Nil(jsoniter.UnmarshalFromString("10", &val))
|
||||
should.Equal("10", val)
|
||||
should.Nil(jsoniter.UnmarshalFromString("10.1", &val))
|
||||
should.Equal("10.1", val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal("10.1", val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
}
|
||||
|
||||
func Test_int_to_string(t *testing.T) {
|
||||
func Test_any_to_int64(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val string
|
||||
should.Nil(jsoniter.UnmarshalFromString(`100`, &val))
|
||||
should.Equal("100", val)
|
||||
}
|
||||
var val int64
|
||||
|
||||
func Test_float_to_string(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val string
|
||||
should.Nil(jsoniter.UnmarshalFromString(`12.0`, &val))
|
||||
should.Equal("12.0", val)
|
||||
}
|
||||
|
||||
func Test_string_to_int(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val int
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(100, val)
|
||||
}
|
||||
should.Equal(int64(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(int64(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(int64(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(int64(10), val)
|
||||
|
||||
func Test_int_to_int(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val int
|
||||
should.Nil(jsoniter.UnmarshalFromString(`100`, &val))
|
||||
should.Equal(100, val)
|
||||
}
|
||||
|
||||
func Test_float_to_int(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val int
|
||||
should.Nil(jsoniter.UnmarshalFromString(`1.23`, &val))
|
||||
should.Equal(1, val)
|
||||
}
|
||||
|
||||
func Test_large_float_to_int(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val int
|
||||
should.Nil(jsoniter.UnmarshalFromString(`-10`, &val))
|
||||
should.Equal(int64(-10), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
|
||||
func Test_string_to_float32(t *testing.T) {
|
||||
func Test_any_to_int(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val int
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(100, val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(10, val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(10, val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(10, val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
|
||||
func Test_any_to_int16(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val int16
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(int16(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(int16(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(int16(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(int16(10), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
|
||||
func Test_any_to_int32(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val int32
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(int32(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(int32(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(int32(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(int32(10), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
|
||||
func Test_any_to_int8(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val int8
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(int8(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(int8(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(int8(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(int8(10), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
|
||||
func Test_any_to_uint8(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val uint8
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(uint8(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(uint8(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(uint8(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(uint8(10), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
|
||||
func Test_any_to_uint64(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val uint64
|
||||
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(uint64(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(uint64(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(uint64(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(uint64(10), val)
|
||||
|
||||
// TODO fix?
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`-10`, &val))
|
||||
should.Equal(uint64(0), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
func Test_any_to_uint32(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val uint32
|
||||
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(uint32(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(uint32(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(uint32(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(uint32(10), val)
|
||||
|
||||
// TODO fix?
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`-10`, &val))
|
||||
should.Equal(uint32(0), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
func Test_any_to_uint16(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val uint16
|
||||
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(uint16(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(uint16(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(uint16(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(uint16(10), val)
|
||||
|
||||
// TODO fix?
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`-10`, &val))
|
||||
should.Equal(uint16(0), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
func Test_any_to_uint(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val uint
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(uint(100), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(uint(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(uint(10), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(uint(10), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
// large float to int
|
||||
should.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
||||
}
|
||||
|
||||
func Test_any_to_float32(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val float32
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(float32(100), val)
|
||||
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(float32(10.1), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(float32(10.1), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(float32(10), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
}
|
||||
|
||||
func Test_float_to_float32(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val float32
|
||||
should.Nil(jsoniter.UnmarshalFromString(`1.23`, &val))
|
||||
should.Equal(float32(1.23), val)
|
||||
}
|
||||
|
||||
func Test_string_to_float64(t *testing.T) {
|
||||
func Test_any_to_float64(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val float64
|
||||
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
||||
should.Equal(float64(100), val)
|
||||
}
|
||||
|
||||
func Test_float_to_float64(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var val float64
|
||||
should.Nil(jsoniter.UnmarshalFromString(`1.23`, &val))
|
||||
should.Equal(float64(1.23), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`"10.1"`, &val))
|
||||
should.Equal(float64(10.1), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10.1`, &val))
|
||||
should.Equal(float64(10.1), val)
|
||||
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
|
||||
should.Equal(float64(10), val)
|
||||
should.NotNil(jsoniter.UnmarshalFromString("{}", &val))
|
||||
should.NotNil(jsoniter.UnmarshalFromString("[]", &val))
|
||||
}
|
||||
|
||||
func Test_empty_array_as_map(t *testing.T) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package jsoniter
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_missing_object_end(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user