mirror of
https://github.com/json-iterator/go.git
synced 2024-12-03 08:45:22 +02:00
88 lines
2.0 KiB
Go
88 lines
2.0 KiB
Go
package extra
|
|
|
|
import (
|
|
"testing"
|
|
"github.com/json-iterator/go"
|
|
"github.com/json-iterator/go/require"
|
|
)
|
|
|
|
func init() {
|
|
RegisterFuzzyDecoders()
|
|
}
|
|
|
|
func Test_string_to_string(t *testing.T) {
|
|
should := require.New(t)
|
|
var val string
|
|
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
|
should.Equal("100", val)
|
|
}
|
|
|
|
func Test_int_to_string(t *testing.T) {
|
|
should := require.New(t)
|
|
var val string
|
|
should.Nil(jsoniter.UnmarshalFromString(`100`, &val))
|
|
should.Equal("100", val)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
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.NotNil(jsoniter.UnmarshalFromString(`1234512345123451234512345.0`, &val))
|
|
}
|
|
|
|
func Test_string_to_float32(t *testing.T) {
|
|
should := require.New(t)
|
|
var val float32
|
|
should.Nil(jsoniter.UnmarshalFromString(`"100"`, &val))
|
|
should.Equal(float32(100), 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) {
|
|
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)
|
|
}
|