| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package jsoniter
- import (
- "github.com/stretchr/testify/require"
- "testing"
- )
- func Test_missing_object_end(t *testing.T) {
- should := require.New(t)
- type TestObject struct {
- Metric string `json:"metric"`
- Tags map[string]interface{} `json:"tags"`
- }
- obj := TestObject{}
- should.NotNil(UnmarshalFromString(`{"metric": "sys.777","tags": {"a":"123"}`, &obj))
- }
- func Test_missing_array_end(t *testing.T) {
- should := require.New(t)
- should.NotNil(UnmarshalFromString(`[1,2,3`, &[]int{}))
- }
- func Test_invalid_any(t *testing.T) {
- should := require.New(t)
- any := Get([]byte("[]"))
- should.Equal(Invalid, any.Get(0.3).ValueType())
- // is nil correct ?
- should.Equal(nil, any.Get(0.3).GetInterface())
- any = any.Get(0.3)
- should.Equal(false, any.ToBool())
- should.Equal(int(0), any.ToInt())
- should.Equal(int32(0), any.ToInt32())
- should.Equal(int64(0), any.ToInt64())
- should.Equal(uint(0), any.ToUint())
- should.Equal(uint32(0), any.ToUint32())
- should.Equal(uint64(0), any.ToUint64())
- should.Equal(float32(0), any.ToFloat32())
- should.Equal(float64(0), any.ToFloat64())
- should.Equal("", any.ToString())
- should.Equal(Invalid, any.Get(0.1).Get(1).ValueType())
- }
|