mirror of
https://github.com/json-iterator/go.git
synced 2025-04-26 11:42:56 +02:00
increase coverage
This commit is contained in:
parent
1745078ab7
commit
550531a046
@ -1,8 +1,8 @@
|
|||||||
package jsoniter
|
package jsoniter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"math"
|
"math"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _POW10 []uint64
|
var _POW10 []uint64
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
package jsoniter
|
package jsoniter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/json-iterator/go/require"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/json-iterator/go/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_new_encoder(t *testing.T) {
|
func Test_new_encoder(t *testing.T) {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package jsoniter
|
package jsoniter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/json-iterator/go/require"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/json-iterator/go/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_read_empty_array_as_any(t *testing.T) {
|
func Test_read_empty_array_as_any(t *testing.T) {
|
||||||
|
@ -44,4 +44,21 @@ func Test_read_bool_as_any(t *testing.T) {
|
|||||||
should.False(any.ToBool(), fmt.Sprintf("origin val is %v", k))
|
should.False(any.ToBool(), fmt.Sprintf("origin val is %v", k))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_write_bool_to_stream(t *testing.T) {
|
||||||
|
should := require.New(t)
|
||||||
|
any := Get([]byte("true"))
|
||||||
|
stream := NewStream(ConfigDefault, nil, 32)
|
||||||
|
any.WriteTo(stream)
|
||||||
|
should.Equal("true", string(stream.Buffer()))
|
||||||
|
should.Equal(any.ValueType(), Bool)
|
||||||
|
|
||||||
|
any = Get([]byte("false"))
|
||||||
|
stream = NewStream(ConfigDefault, nil, 32)
|
||||||
|
any.WriteTo(stream)
|
||||||
|
should.Equal("false", string(stream.Buffer()))
|
||||||
|
|
||||||
|
should.Equal(any.ValueType(), Bool)
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,10 @@ func Test_read_int64_to_any(t *testing.T) {
|
|||||||
should.Equal(float64(12345), any.ToFloat64())
|
should.Equal(float64(12345), any.ToFloat64())
|
||||||
should.Equal("12345", any.ToString())
|
should.Equal("12345", any.ToString())
|
||||||
should.Equal(true, any.ToBool())
|
should.Equal(true, any.ToBool())
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
stream := NewStream(ConfigDefault, nil, 32)
|
||||||
|
any.WriteTo(stream)
|
||||||
|
should.Equal("12345", string(stream.Buffer()))
|
||||||
}
|
}
|
||||||
func Test_read_int32_to_any(t *testing.T) {
|
func Test_read_int32_to_any(t *testing.T) {
|
||||||
should := require.New(t)
|
should := require.New(t)
|
||||||
@ -137,6 +141,10 @@ func Test_read_int32_to_any(t *testing.T) {
|
|||||||
should.Equal(float64(12345), any.ToFloat64())
|
should.Equal(float64(12345), any.ToFloat64())
|
||||||
should.Equal("12345", any.ToString())
|
should.Equal("12345", any.ToString())
|
||||||
should.Equal(true, any.ToBool())
|
should.Equal(true, any.ToBool())
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
stream := NewStream(ConfigDefault, nil, 32)
|
||||||
|
any.WriteTo(stream)
|
||||||
|
should.Equal("12345", string(stream.Buffer()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_read_uint32_to_any(t *testing.T) {
|
func Test_read_uint32_to_any(t *testing.T) {
|
||||||
@ -153,6 +161,9 @@ func Test_read_uint32_to_any(t *testing.T) {
|
|||||||
should.Equal("12345", any.ToString())
|
should.Equal("12345", any.ToString())
|
||||||
should.Equal(true, any.ToBool())
|
should.Equal(true, any.ToBool())
|
||||||
should.Equal(any.ValueType(), Number)
|
should.Equal(any.ValueType(), Number)
|
||||||
|
stream := NewStream(ConfigDefault, nil, 32)
|
||||||
|
any.WriteTo(stream)
|
||||||
|
should.Equal("12345", string(stream.Buffer()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_read_uint64_to_any(t *testing.T) {
|
func Test_read_uint64_to_any(t *testing.T) {
|
||||||
@ -169,6 +180,9 @@ func Test_read_uint64_to_any(t *testing.T) {
|
|||||||
should.Equal("12345", any.ToString())
|
should.Equal("12345", any.ToString())
|
||||||
should.Equal(true, any.ToBool())
|
should.Equal(true, any.ToBool())
|
||||||
should.Equal(any.ValueType(), Number)
|
should.Equal(any.ValueType(), Number)
|
||||||
|
stream := NewStream(ConfigDefault, nil, 32)
|
||||||
|
any.WriteTo(stream)
|
||||||
|
should.Equal("12345", string(stream.Buffer()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_int_lazy_any_get(t *testing.T) {
|
func Test_int_lazy_any_get(t *testing.T) {
|
||||||
|
@ -3,8 +3,9 @@ package jsoniter
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/json-iterator/go/require"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/json-iterator/go/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_empty_object(t *testing.T) {
|
func Test_empty_object(t *testing.T) {
|
||||||
@ -381,7 +382,7 @@ func Test_shadow_struct_field(t *testing.T) {
|
|||||||
should.Contains(output, `"max_age":20`)
|
should.Contains(output, `"max_age":20`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_embeded_order(t *testing.T) {
|
func Test_embedded_order(t *testing.T) {
|
||||||
type A struct {
|
type A struct {
|
||||||
Field2 string
|
Field2 string
|
||||||
}
|
}
|
||||||
|
41
wrap_test.go
Normal file
41
wrap_test.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package jsoniter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/json-iterator/go/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_wrap_and_valuetype_everything(t *testing.T) {
|
||||||
|
should := require.New(t)
|
||||||
|
any := Wrap(int8(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
any = Wrap(int16(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
any = Wrap(int32(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
any = Wrap(int64(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
|
||||||
|
any = Wrap(uint(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
any = Wrap(uint8(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
any = Wrap(uint16(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
any = Wrap(uint32(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
any = Wrap(uint64(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
|
||||||
|
any = Wrap(float32(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
any = Wrap(float64(10))
|
||||||
|
should.Equal(any.ValueType(), Number)
|
||||||
|
|
||||||
|
any = Wrap(true)
|
||||||
|
should.Equal(any.ValueType(), Bool)
|
||||||
|
any = Wrap(false)
|
||||||
|
should.Equal(any.ValueType(), Bool)
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user