1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-27 08:30:57 +02:00

rename ValueType, to avoid collision with json.Number

This commit is contained in:
Tao Wen 2017-08-05 07:10:15 +08:00
parent abbd16da6c
commit d249b05a85
26 changed files with 110 additions and 110 deletions

View File

@ -158,7 +158,7 @@ type tolerateEmptyArrayDecoder struct {
} }
func (decoder *tolerateEmptyArrayDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { func (decoder *tolerateEmptyArrayDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
if iter.WhatIsNext() == jsoniter.Array { if iter.WhatIsNext() == jsoniter.ArrayValue {
iter.Skip() iter.Skip()
newIter := iter.Pool().BorrowIterator([]byte("{}")) newIter := iter.Pool().BorrowIterator([]byte("{}"))
defer iter.Pool().ReturnIterator(newIter) defer iter.Pool().ReturnIterator(newIter)
@ -174,11 +174,11 @@ type fuzzyStringDecoder struct {
func (decoder *fuzzyStringDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { func (decoder *fuzzyStringDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
valueType := iter.WhatIsNext() valueType := iter.WhatIsNext()
switch valueType { switch valueType {
case jsoniter.Number: case jsoniter.NumberValue:
var number json.Number var number json.Number
iter.ReadVal(&number) iter.ReadVal(&number)
*((*string)(ptr)) = string(number) *((*string)(ptr)) = string(number)
case jsoniter.String: case jsoniter.StringValue:
*((*string)(ptr)) = iter.ReadString() *((*string)(ptr)) = iter.ReadString()
default: default:
iter.ReportError("fuzzyStringDecoder", "not number or string") iter.ReportError("fuzzyStringDecoder", "not number or string")
@ -193,11 +193,11 @@ func (decoder *fuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
valueType := iter.WhatIsNext() valueType := iter.WhatIsNext()
var str string var str string
switch valueType { switch valueType {
case jsoniter.Number: case jsoniter.NumberValue:
var number json.Number var number json.Number
iter.ReadVal(&number) iter.ReadVal(&number)
str = string(number) str = string(number)
case jsoniter.String: case jsoniter.StringValue:
str = iter.ReadString() str = iter.ReadString()
default: default:
iter.ReportError("fuzzyIntegerDecoder", "not number or string") iter.ReportError("fuzzyIntegerDecoder", "not number or string")
@ -218,9 +218,9 @@ func (decoder *fuzzyFloat32Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
valueType := iter.WhatIsNext() valueType := iter.WhatIsNext()
var str string var str string
switch valueType { switch valueType {
case jsoniter.Number: case jsoniter.NumberValue:
*((*float32)(ptr)) = iter.ReadFloat32() *((*float32)(ptr)) = iter.ReadFloat32()
case jsoniter.String: case jsoniter.StringValue:
str = iter.ReadString() str = iter.ReadString()
newIter := iter.Pool().BorrowIterator([]byte(str)) newIter := iter.Pool().BorrowIterator([]byte(str))
defer iter.Pool().ReturnIterator(newIter) defer iter.Pool().ReturnIterator(newIter)
@ -240,9 +240,9 @@ func (decoder *fuzzyFloat64Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
valueType := iter.WhatIsNext() valueType := iter.WhatIsNext()
var str string var str string
switch valueType { switch valueType {
case jsoniter.Number: case jsoniter.NumberValue:
*((*float64)(ptr)) = iter.ReadFloat64() *((*float64)(ptr)) = iter.ReadFloat64()
case jsoniter.String: case jsoniter.StringValue:
str = iter.ReadString() str = iter.ReadString()
newIter := iter.Pool().BorrowIterator([]byte(str)) newIter := iter.Pool().BorrowIterator([]byte(str))
defer iter.Pool().ReturnIterator(newIter) defer iter.Pool().ReturnIterator(newIter)

View File

@ -90,7 +90,7 @@ func (adapter *Decoder) Buffered() io.Reader {
return bytes.NewReader(remaining) return bytes.NewReader(remaining)
} }
// UseNumber for number JSON element, use float64 or json.Number (alias of string) // UseNumber for number JSON element, use float64 or json.NumberValue (alias of string)
func (adapter *Decoder) UseNumber() { func (adapter *Decoder) UseNumber() {
origCfg := adapter.iter.cfg.configBeforeFrozen origCfg := adapter.iter.cfg.configBeforeFrozen
origCfg.UseNumber = true origCfg.UseNumber = true

View File

@ -13,7 +13,7 @@ type arrayLazyAny struct {
} }
func (any *arrayLazyAny) ValueType() ValueType { func (any *arrayLazyAny) ValueType() ValueType {
return Array return ArrayValue
} }
func (any *arrayLazyAny) MustBeValid() Any { func (any *arrayLazyAny) MustBeValid() Any {
@ -117,7 +117,7 @@ func (any *arrayLazyAny) Get(path ...interface{}) Any {
arr := make([]Any, 0) arr := make([]Any, 0)
iter.ReadArrayCB(func(iter *Iterator) bool { iter.ReadArrayCB(func(iter *Iterator) bool {
found := iter.readAny().Get(path[1:]...) found := iter.readAny().Get(path[1:]...)
if found.ValueType() != Invalid { if found.ValueType() != InvalidValue {
arr = append(arr, found) arr = append(arr, found)
} }
return true return true
@ -162,7 +162,7 @@ func wrapArray(val interface{}) *arrayAny {
} }
func (any *arrayAny) ValueType() ValueType { func (any *arrayAny) ValueType() ValueType {
return Array return ArrayValue
} }
func (any *arrayAny) MustBeValid() Any { func (any *arrayAny) MustBeValid() Any {
@ -253,7 +253,7 @@ func (any *arrayAny) Get(path ...interface{}) Any {
mappedAll := make([]Any, 0) mappedAll := make([]Any, 0)
for i := 0; i < any.val.Len(); i++ { for i := 0; i < any.val.Len(); i++ {
mapped := Wrap(any.val.Index(i).Interface()).Get(path[1:]...) mapped := Wrap(any.val.Index(i).Interface()).Get(path[1:]...)
if mapped.ValueType() != Invalid { if mapped.ValueType() != InvalidValue {
mappedAll = append(mappedAll, mapped) mappedAll = append(mappedAll, mapped)
} }
} }

View File

@ -61,7 +61,7 @@ func (any *trueAny) GetInterface() interface{} {
} }
func (any *trueAny) ValueType() ValueType { func (any *trueAny) ValueType() ValueType {
return Bool return BoolValue
} }
func (any *trueAny) MustBeValid() Any { func (any *trueAny) MustBeValid() Any {
@ -129,7 +129,7 @@ func (any *falseAny) GetInterface() interface{} {
} }
func (any *falseAny) ValueType() ValueType { func (any *falseAny) ValueType() ValueType {
return Bool return BoolValue
} }
func (any *falseAny) MustBeValid() Any { func (any *falseAny) MustBeValid() Any {

View File

@ -14,7 +14,7 @@ func (any *floatAny) Parse() *Iterator {
} }
func (any *floatAny) ValueType() ValueType { func (any *floatAny) ValueType() ValueType {
return Number return NumberValue
} }
func (any *floatAny) MustBeValid() Any { func (any *floatAny) MustBeValid() Any {

View File

@ -14,7 +14,7 @@ func (any *int32Any) LastError() error {
} }
func (any *int32Any) ValueType() ValueType { func (any *int32Any) ValueType() ValueType {
return Number return NumberValue
} }
func (any *int32Any) MustBeValid() Any { func (any *int32Any) MustBeValid() Any {

View File

@ -14,7 +14,7 @@ func (any *int64Any) LastError() error {
} }
func (any *int64Any) ValueType() ValueType { func (any *int64Any) ValueType() ValueType {
return Number return NumberValue
} }
func (any *int64Any) MustBeValid() Any { func (any *int64Any) MustBeValid() Any {

View File

@ -16,7 +16,7 @@ func (any *invalidAny) LastError() error {
} }
func (any *invalidAny) ValueType() ValueType { func (any *invalidAny) ValueType() ValueType {
return Invalid return InvalidValue
} }
func (any *invalidAny) MustBeValid() Any { func (any *invalidAny) MustBeValid() Any {

View File

@ -9,7 +9,7 @@ func (any *nilAny) LastError() error {
} }
func (any *nilAny) ValueType() ValueType { func (any *nilAny) ValueType() ValueType {
return Nil return NilValue
} }
func (any *nilAny) MustBeValid() Any { func (any *nilAny) MustBeValid() Any {

View File

@ -10,7 +10,7 @@ type numberLazyAny struct {
} }
func (any *numberLazyAny) ValueType() ValueType { func (any *numberLazyAny) ValueType() ValueType {
return Number return NumberValue
} }
func (any *numberLazyAny) MustBeValid() Any { func (any *numberLazyAny) MustBeValid() Any {

View File

@ -13,7 +13,7 @@ type objectLazyAny struct {
} }
func (any *objectLazyAny) ValueType() ValueType { func (any *objectLazyAny) ValueType() ValueType {
return Object return ObjectValue
} }
func (any *objectLazyAny) MustBeValid() Any { func (any *objectLazyAny) MustBeValid() Any {
@ -91,7 +91,7 @@ func (any *objectLazyAny) Get(path ...interface{}) Any {
defer any.cfg.ReturnIterator(iter) defer any.cfg.ReturnIterator(iter)
iter.ReadMapCB(func(iter *Iterator, field string) bool { iter.ReadMapCB(func(iter *Iterator, field string) bool {
mapped := locatePath(iter, path[1:]) mapped := locatePath(iter, path[1:])
if mapped.ValueType() != Invalid { if mapped.ValueType() != InvalidValue {
mappedAll[field] = mapped mappedAll[field] = mapped
} }
return true return true
@ -149,7 +149,7 @@ func wrapStruct(val interface{}) *objectAny {
} }
func (any *objectAny) ValueType() ValueType { func (any *objectAny) ValueType() ValueType {
return Object return ObjectValue
} }
func (any *objectAny) MustBeValid() Any { func (any *objectAny) MustBeValid() Any {
@ -224,7 +224,7 @@ func (any *objectAny) Get(path ...interface{}) Any {
field := any.val.Field(i) field := any.val.Field(i)
if field.CanInterface() { if field.CanInterface() {
mapped := Wrap(field.Interface()).Get(path[1:]...) mapped := Wrap(field.Interface()).Get(path[1:]...)
if mapped.ValueType() != Invalid { if mapped.ValueType() != InvalidValue {
mappedAll[any.val.Type().Field(i).Name] = mapped mappedAll[any.val.Type().Field(i).Name] = mapped
} }
} }
@ -268,7 +268,7 @@ func wrapMap(val interface{}) *mapAny {
} }
func (any *mapAny) ValueType() ValueType { func (any *mapAny) ValueType() ValueType {
return Object return ObjectValue
} }
func (any *mapAny) MustBeValid() Any { func (any *mapAny) MustBeValid() Any {
@ -337,7 +337,7 @@ func (any *mapAny) Get(path ...interface{}) Any {
keyAsStr := key.String() keyAsStr := key.String()
element := Wrap(any.val.MapIndex(key).Interface()) element := Wrap(any.val.MapIndex(key).Interface())
mapped := element.Get(path[1:]...) mapped := element.Get(path[1:]...)
if mapped.ValueType() != Invalid { if mapped.ValueType() != InvalidValue {
mappedAll[keyAsStr] = mapped mappedAll[keyAsStr] = mapped
} }
} }

View File

@ -22,7 +22,7 @@ func (any *stringAny) Parse() *Iterator {
} }
func (any *stringAny) ValueType() ValueType { func (any *stringAny) ValueType() ValueType {
return String return StringValue
} }
func (any *stringAny) MustBeValid() Any { func (any *stringAny) MustBeValid() Any {

View File

@ -14,7 +14,7 @@ func (any *uint32Any) LastError() error {
} }
func (any *uint32Any) ValueType() ValueType { func (any *uint32Any) ValueType() ValueType {
return Number return NumberValue
} }
func (any *uint32Any) MustBeValid() Any { func (any *uint32Any) MustBeValid() Any {

View File

@ -14,7 +14,7 @@ func (any *uint64Any) LastError() error {
} }
func (any *uint64Any) ValueType() ValueType { func (any *uint64Any) ValueType() ValueType {
return Number return NumberValue
} }
func (any *uint64Any) MustBeValid() Any { func (any *uint64Any) MustBeValid() Any {

View File

@ -88,7 +88,7 @@ func (cfg Config) Froze() API {
func (cfg *frozenConfig) useNumber() { func (cfg *frozenConfig) useNumber() {
cfg.addDecoderToCache(reflect.TypeOf((*interface{})(nil)).Elem(), &funcDecoder{func(ptr unsafe.Pointer, iter *Iterator) { cfg.addDecoderToCache(reflect.TypeOf((*interface{})(nil)).Elem(), &funcDecoder{func(ptr unsafe.Pointer, iter *Iterator) {
if iter.WhatIsNext() == Number { if iter.WhatIsNext() == NumberValue {
*((*interface{})(ptr)) = json.Number(iter.readNumberAsString()) *((*interface{})(ptr)) = json.Number(iter.readNumberAsString())
} else { } else {
*((*interface{})(ptr)) = iter.Read() *((*interface{})(ptr)) = iter.Read()

View File

@ -10,20 +10,20 @@ import (
type ValueType int type ValueType int
const ( const (
// Invalid invalid JSON element // InvalidValue invalid JSON element
Invalid ValueType = iota InvalidValue ValueType = iota
// String JSON element "string" // StringValue JSON element "string"
String StringValue
// Number JSON element 100 or 0.10 // NumberValue JSON element 100 or 0.10
Number NumberValue
// Nil JSON element null // NilValue JSON element null
Nil NilValue
// Bool JSON element true or false // BoolValue JSON element true or false
Bool BoolValue
// Array JSON element [] // ArrayValue JSON element []
Array ArrayValue
// Object JSON element {} // ObjectValue JSON element {}
Object ObjectValue
) )
var hexDigits []byte var hexDigits []byte
@ -45,25 +45,25 @@ func init() {
} }
valueTypes = make([]ValueType, 256) valueTypes = make([]ValueType, 256)
for i := 0; i < len(valueTypes); i++ { for i := 0; i < len(valueTypes); i++ {
valueTypes[i] = Invalid valueTypes[i] = InvalidValue
} }
valueTypes['"'] = String valueTypes['"'] = StringValue
valueTypes['-'] = Number valueTypes['-'] = NumberValue
valueTypes['0'] = Number valueTypes['0'] = NumberValue
valueTypes['1'] = Number valueTypes['1'] = NumberValue
valueTypes['2'] = Number valueTypes['2'] = NumberValue
valueTypes['3'] = Number valueTypes['3'] = NumberValue
valueTypes['4'] = Number valueTypes['4'] = NumberValue
valueTypes['5'] = Number valueTypes['5'] = NumberValue
valueTypes['6'] = Number valueTypes['6'] = NumberValue
valueTypes['7'] = Number valueTypes['7'] = NumberValue
valueTypes['8'] = Number valueTypes['8'] = NumberValue
valueTypes['9'] = Number valueTypes['9'] = NumberValue
valueTypes['t'] = Bool valueTypes['t'] = BoolValue
valueTypes['f'] = Bool valueTypes['f'] = BoolValue
valueTypes['n'] = Nil valueTypes['n'] = NilValue
valueTypes['['] = Array valueTypes['['] = ArrayValue
valueTypes['{'] = Object valueTypes['{'] = ObjectValue
} }
// Iterator is a io.Reader like object, with JSON specific read functions. // Iterator is a io.Reader like object, with JSON specific read functions.
@ -270,26 +270,26 @@ func (iter *Iterator) unreadByte() {
func (iter *Iterator) Read() interface{} { func (iter *Iterator) Read() interface{} {
valueType := iter.WhatIsNext() valueType := iter.WhatIsNext()
switch valueType { switch valueType {
case String: case StringValue:
return iter.ReadString() return iter.ReadString()
case Number: case NumberValue:
if iter.cfg.configBeforeFrozen.UseNumber { if iter.cfg.configBeforeFrozen.UseNumber {
return json.Number(iter.readNumberAsString()) return json.Number(iter.readNumberAsString())
} }
return iter.ReadFloat64() return iter.ReadFloat64()
case Nil: case NilValue:
iter.skipFourBytes('n', 'u', 'l', 'l') iter.skipFourBytes('n', 'u', 'l', 'l')
return nil return nil
case Bool: case BoolValue:
return iter.ReadBool() return iter.ReadBool()
case Array: case ArrayValue:
arr := []interface{}{} arr := []interface{}{}
iter.ReadArrayCB(func(iter *Iterator) bool { iter.ReadArrayCB(func(iter *Iterator) bool {
arr = append(arr, iter.Read()) arr = append(arr, iter.Read())
return true return true
}) })
return arr return arr
case Object: case ObjectValue:
obj := map[string]interface{}{} obj := map[string]interface{}{}
iter.ReadMapCB(func(Iter *Iterator, field string) bool { iter.ReadMapCB(func(Iter *Iterator, field string) bool {
obj[field] = iter.Read() obj[field] = iter.Read()

View File

@ -14,7 +14,7 @@ func (iter *Iterator) ReadNil() (ret bool) {
return false return false
} }
// ReadBool reads a json object as Bool // ReadBool reads a json object as BoolValue
func (iter *Iterator) ReadBool() (ret bool) { func (iter *Iterator) ReadBool() (ret bool) {
c := iter.nextToken() c := iter.nextToken()
if c == 't' { if c == 't' {

View File

@ -436,7 +436,7 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
return return
} }
switch iter.WhatIsNext() { switch iter.WhatIsNext() {
case String: case StringValue:
encoding := base64.StdEncoding encoding := base64.StdEncoding
src := iter.SkipAndReturnBytes() src := iter.SkipAndReturnBytes()
src = src[1 : len(src)-1] src = src[1 : len(src)-1]
@ -453,7 +453,7 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
ptrSlice.Cap = dstSlice.Cap ptrSlice.Cap = dstSlice.Cap
ptrSlice.Len = dstSlice.Len ptrSlice.Len = dstSlice.Len
} }
case Array: case ArrayValue:
codec.sliceDecoder.Decode(ptr, iter) codec.sliceDecoder.Decode(ptr, iter)
default: default:
iter.ReportError("base64Codec", "invalid input") iter.ReportError("base64Codec", "invalid input")

View File

@ -456,7 +456,7 @@ type skipObjectDecoder struct {
func (decoder *skipObjectDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { func (decoder *skipObjectDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
valueType := iter.WhatIsNext() valueType := iter.WhatIsNext()
if valueType != Object && valueType != Nil { if valueType != ObjectValue && valueType != NilValue {
iter.ReportError("skipObjectDecoder", "expect object or null") iter.ReportError("skipObjectDecoder", "expect object or null")
return return
} }

View File

@ -9,10 +9,10 @@ import (
func Test_read_empty_array_as_any(t *testing.T) { func Test_read_empty_array_as_any(t *testing.T) {
should := require.New(t) should := require.New(t)
any := Get([]byte("[]")) any := Get([]byte("[]"))
should.Equal(Array, any.Get().ValueType()) should.Equal(ArrayValue, any.Get().ValueType())
should.Equal(Invalid, any.Get(0.3).ValueType()) should.Equal(InvalidValue, any.Get(0.3).ValueType())
should.Equal(0, any.Size()) should.Equal(0, any.Size())
should.Equal(Array, any.ValueType()) should.Equal(ArrayValue, any.ValueType())
should.Nil(any.LastError()) should.Nil(any.LastError())
should.Equal(0, any.ToInt()) should.Equal(0, any.ToInt())
should.Equal(int32(0), any.ToInt32()) should.Equal(int32(0), any.ToInt32())
@ -101,7 +101,7 @@ func Test_array_wrapper_any_get_all(t *testing.T) {
{5, 6}, {5, 6},
}) })
should.Equal("[1,3,5]", any.Get('*', 0).ToString()) should.Equal("[1,3,5]", any.Get('*', 0).ToString())
should.Equal(Array, any.ValueType()) should.Equal(ArrayValue, any.ValueType())
should.True(any.ToBool()) should.True(any.ToBool())
should.Equal(1, any.Get(0, 0).ToInt()) should.Equal(1, any.Get(0, 0).ToInt())
} }
@ -109,14 +109,14 @@ func Test_array_wrapper_any_get_all(t *testing.T) {
func Test_array_lazy_any_get_invalid(t *testing.T) { func Test_array_lazy_any_get_invalid(t *testing.T) {
should := require.New(t) should := require.New(t)
any := Get([]byte("[]")) any := Get([]byte("[]"))
should.Equal(Invalid, any.Get(1, 1).ValueType()) should.Equal(InvalidValue, any.Get(1, 1).ValueType())
should.NotNil(any.Get(1, 1).LastError()) should.NotNil(any.Get(1, 1).LastError())
should.Equal(Invalid, any.Get("1").ValueType()) should.Equal(InvalidValue, any.Get("1").ValueType())
should.NotNil(any.Get("1").LastError()) should.NotNil(any.Get("1").LastError())
} }
func Test_invalid_array(t *testing.T) { func Test_invalid_array(t *testing.T) {
should := require.New(t) should := require.New(t)
any := Get([]byte("["), 0) any := Get([]byte("["), 0)
should.Equal(Invalid, any.ValueType()) should.Equal(InvalidValue, any.ValueType())
} }

View File

@ -53,12 +53,12 @@ func Test_write_bool_to_stream(t *testing.T) {
stream := NewStream(ConfigDefault, nil, 32) stream := NewStream(ConfigDefault, nil, 32)
any.WriteTo(stream) any.WriteTo(stream)
should.Equal("true", string(stream.Buffer())) should.Equal("true", string(stream.Buffer()))
should.Equal(any.ValueType(), Bool) should.Equal(any.ValueType(), BoolValue)
any = Get([]byte("false")) any = Get([]byte("false"))
stream = NewStream(ConfigDefault, nil, 32) stream = NewStream(ConfigDefault, nil, 32)
any.WriteTo(stream) any.WriteTo(stream)
should.Equal("false", string(stream.Buffer())) should.Equal("false", string(stream.Buffer()))
should.Equal(any.ValueType(), Bool) should.Equal(any.ValueType(), BoolValue)
} }

View File

@ -96,7 +96,7 @@ func Test_read_float_to_any(t *testing.T) {
should.Equal(uint(0), any2.ToUint()) should.Equal(uint(0), any2.ToUint())
should.Equal(uint32(0), any2.ToUint32()) should.Equal(uint32(0), any2.ToUint32())
should.Equal(uint64(0), any2.ToUint64()) should.Equal(uint64(0), any2.ToUint64())
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal("1.23E+01", any.ToString()) should.Equal("1.23E+01", any.ToString())
} }

View File

@ -123,7 +123,7 @@ 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) should.Equal(any.ValueType(), NumberValue)
stream := NewStream(ConfigDefault, nil, 32) stream := NewStream(ConfigDefault, nil, 32)
any.WriteTo(stream) any.WriteTo(stream)
should.Equal("12345", string(stream.Buffer())) should.Equal("12345", string(stream.Buffer()))
@ -141,7 +141,7 @@ 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) should.Equal(any.ValueType(), NumberValue)
stream := NewStream(ConfigDefault, nil, 32) stream := NewStream(ConfigDefault, nil, 32)
any.WriteTo(stream) any.WriteTo(stream)
should.Equal("12345", string(stream.Buffer())) should.Equal("12345", string(stream.Buffer()))
@ -160,7 +160,7 @@ func Test_read_uint32_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) should.Equal(any.ValueType(), NumberValue)
stream := NewStream(ConfigDefault, nil, 32) stream := NewStream(ConfigDefault, nil, 32)
any.WriteTo(stream) any.WriteTo(stream)
should.Equal("12345", string(stream.Buffer())) should.Equal("12345", string(stream.Buffer()))
@ -179,7 +179,7 @@ func Test_read_uint64_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) should.Equal(any.ValueType(), NumberValue)
stream := NewStream(ConfigDefault, nil, 32) stream := NewStream(ConfigDefault, nil, 32)
any.WriteTo(stream) any.WriteTo(stream)
should.Equal("12345", string(stream.Buffer())) should.Equal("12345", string(stream.Buffer()))
@ -193,5 +193,5 @@ func Test_int_lazy_any_get(t *testing.T) {
any := Get([]byte("1234")) any := Get([]byte("1234"))
// panic!! // panic!!
//should.Equal(any.LastError(), io.EOF) //should.Equal(any.LastError(), io.EOF)
should.Equal(Invalid, any.Get(1, "2").ValueType()) should.Equal(InvalidValue, any.Get(1, "2").ValueType())
} }

View File

@ -20,7 +20,7 @@ func Test_read_object_as_any(t *testing.T) {
should.Equal(2, any.Size()) should.Equal(2, any.Size())
should.True(any.ToBool()) should.True(any.ToBool())
should.Equal(0, any.ToInt()) should.Equal(0, any.ToInt())
should.Equal(Object, any.ValueType()) should.Equal(ObjectValue, any.ValueType())
should.Nil(any.LastError()) should.Nil(any.LastError())
obj := struct { obj := struct {
A string A string
@ -44,8 +44,8 @@ func Test_object_lazy_any_get_all(t *testing.T) {
func Test_object_lazy_any_get_invalid(t *testing.T) { func Test_object_lazy_any_get_invalid(t *testing.T) {
should := require.New(t) should := require.New(t)
any := Get([]byte(`{}`)) any := Get([]byte(`{}`))
should.Equal(Invalid, any.Get("a", "stream", "c").ValueType()) should.Equal(InvalidValue, any.Get("a", "stream", "c").ValueType())
should.Equal(Invalid, any.Get(1).ValueType()) should.Equal(InvalidValue, any.Get(1).ValueType())
} }
func Test_wrap_map_and_convert_to_any(t *testing.T) { func Test_wrap_map_and_convert_to_any(t *testing.T) {

View File

@ -25,7 +25,7 @@ func Test_missing_array_end(t *testing.T) {
func Test_invalid_any(t *testing.T) { func Test_invalid_any(t *testing.T) {
should := require.New(t) should := require.New(t)
any := Get([]byte("[]")) any := Get([]byte("[]"))
should.Equal(Invalid, any.Get(0.3).ValueType()) should.Equal(InvalidValue, any.Get(0.3).ValueType())
// is nil correct ? // is nil correct ?
should.Equal(nil, any.Get(0.3).GetInterface()) should.Equal(nil, any.Get(0.3).GetInterface())
@ -41,7 +41,7 @@ func Test_invalid_any(t *testing.T) {
should.Equal(float64(0), any.ToFloat64()) should.Equal(float64(0), any.ToFloat64())
should.Equal("", any.ToString()) should.Equal("", any.ToString())
should.Equal(Invalid, any.Get(0.1).Get(1).ValueType()) should.Equal(InvalidValue, any.Get(0.1).Get(1).ValueType())
} }
func Test_invalid_struct_input(t *testing.T) { func Test_invalid_struct_input(t *testing.T) {

View File

@ -15,80 +15,80 @@ func Test_wrap_and_valuetype_everything(t *testing.T) {
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(int8(10)) any = Wrap(int8(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
// get interface is not int8 interface // get interface is not int8 interface
// i = int8(10) // i = int8(10)
// should.Equal(i, any.GetInterface()) // should.Equal(i, any.GetInterface())
any = Wrap(int16(10)) any = Wrap(int16(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
//i = int16(10) //i = int16(10)
//should.Equal(i, any.GetInterface()) //should.Equal(i, any.GetInterface())
any = Wrap(int32(10)) any = Wrap(int32(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = int32(10) i = int32(10)
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(int64(10)) any = Wrap(int64(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = int64(10) i = int64(10)
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(uint(10)) any = Wrap(uint(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
// not equal // not equal
//i = uint(10) //i = uint(10)
//should.Equal(i, any.GetInterface()) //should.Equal(i, any.GetInterface())
any = Wrap(uint8(10)) any = Wrap(uint8(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
// not equal // not equal
// i = uint8(10) // i = uint8(10)
// should.Equal(i, any.GetInterface()) // should.Equal(i, any.GetInterface())
any = Wrap(uint16(10)) any = Wrap(uint16(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
any = Wrap(uint32(10)) any = Wrap(uint32(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = uint32(10) i = uint32(10)
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(uint64(10)) any = Wrap(uint64(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = uint64(10) i = uint64(10)
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(float32(10)) any = Wrap(float32(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
// not equal // not equal
//i = float32(10) //i = float32(10)
//should.Equal(i, any.GetInterface()) //should.Equal(i, any.GetInterface())
any = Wrap(float64(10)) any = Wrap(float64(10))
should.Equal(any.ValueType(), Number) should.Equal(any.ValueType(), NumberValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = float64(10) i = float64(10)
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(true) any = Wrap(true)
should.Equal(any.ValueType(), Bool) should.Equal(any.ValueType(), BoolValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = true i = true
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(false) any = Wrap(false)
should.Equal(any.ValueType(), Bool) should.Equal(any.ValueType(), BoolValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = false i = false
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(nil) any = Wrap(nil)
should.Equal(any.ValueType(), Nil) should.Equal(any.ValueType(), NilValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = nil i = nil
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
@ -99,13 +99,13 @@ func Test_wrap_and_valuetype_everything(t *testing.T) {
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
any = Wrap(struct{ age int }{age: 1}) any = Wrap(struct{ age int }{age: 1})
should.Equal(any.ValueType(), Object) should.Equal(any.ValueType(), ObjectValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = struct{ age int }{age: 1} i = struct{ age int }{age: 1}
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())
any = Wrap(map[string]interface{}{"abc": 1}) any = Wrap(map[string]interface{}{"abc": 1})
should.Equal(any.ValueType(), Object) should.Equal(any.ValueType(), ObjectValue)
should.Equal(any.LastError(), nil) should.Equal(any.LastError(), nil)
i = map[string]interface{}{"abc": 1} i = map[string]interface{}{"abc": 1}
should.Equal(i, any.GetInterface()) should.Equal(i, any.GetInterface())