You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	rename ValueType, to avoid collision with json.Number
This commit is contained in:
		| @@ -158,7 +158,7 @@ type tolerateEmptyArrayDecoder struct { | ||||
| } | ||||
|  | ||||
| func (decoder *tolerateEmptyArrayDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { | ||||
| 	if iter.WhatIsNext() == jsoniter.Array { | ||||
| 	if iter.WhatIsNext() == jsoniter.ArrayValue { | ||||
| 		iter.Skip() | ||||
| 		newIter := iter.Pool().BorrowIterator([]byte("{}")) | ||||
| 		defer iter.Pool().ReturnIterator(newIter) | ||||
| @@ -174,11 +174,11 @@ type fuzzyStringDecoder struct { | ||||
| func (decoder *fuzzyStringDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { | ||||
| 	valueType := iter.WhatIsNext() | ||||
| 	switch valueType { | ||||
| 	case jsoniter.Number: | ||||
| 	case jsoniter.NumberValue: | ||||
| 		var number json.Number | ||||
| 		iter.ReadVal(&number) | ||||
| 		*((*string)(ptr)) = string(number) | ||||
| 	case jsoniter.String: | ||||
| 	case jsoniter.StringValue: | ||||
| 		*((*string)(ptr)) = iter.ReadString() | ||||
| 	default: | ||||
| 		iter.ReportError("fuzzyStringDecoder", "not number or string") | ||||
| @@ -193,11 +193,11 @@ func (decoder *fuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It | ||||
| 	valueType := iter.WhatIsNext() | ||||
| 	var str string | ||||
| 	switch valueType { | ||||
| 	case jsoniter.Number: | ||||
| 	case jsoniter.NumberValue: | ||||
| 		var number json.Number | ||||
| 		iter.ReadVal(&number) | ||||
| 		str = string(number) | ||||
| 	case jsoniter.String: | ||||
| 	case jsoniter.StringValue: | ||||
| 		str = iter.ReadString() | ||||
| 	default: | ||||
| 		iter.ReportError("fuzzyIntegerDecoder", "not number or string") | ||||
| @@ -218,9 +218,9 @@ func (decoder *fuzzyFloat32Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It | ||||
| 	valueType := iter.WhatIsNext() | ||||
| 	var str string | ||||
| 	switch valueType { | ||||
| 	case jsoniter.Number: | ||||
| 	case jsoniter.NumberValue: | ||||
| 		*((*float32)(ptr)) = iter.ReadFloat32() | ||||
| 	case jsoniter.String: | ||||
| 	case jsoniter.StringValue: | ||||
| 		str = iter.ReadString() | ||||
| 		newIter := iter.Pool().BorrowIterator([]byte(str)) | ||||
| 		defer iter.Pool().ReturnIterator(newIter) | ||||
| @@ -240,9 +240,9 @@ func (decoder *fuzzyFloat64Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It | ||||
| 	valueType := iter.WhatIsNext() | ||||
| 	var str string | ||||
| 	switch valueType { | ||||
| 	case jsoniter.Number: | ||||
| 	case jsoniter.NumberValue: | ||||
| 		*((*float64)(ptr)) = iter.ReadFloat64() | ||||
| 	case jsoniter.String: | ||||
| 	case jsoniter.StringValue: | ||||
| 		str = iter.ReadString() | ||||
| 		newIter := iter.Pool().BorrowIterator([]byte(str)) | ||||
| 		defer iter.Pool().ReturnIterator(newIter) | ||||
|   | ||||
| @@ -90,7 +90,7 @@ func (adapter *Decoder) Buffered() io.Reader { | ||||
| 	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() { | ||||
| 	origCfg := adapter.iter.cfg.configBeforeFrozen | ||||
| 	origCfg.UseNumber = true | ||||
|   | ||||
| @@ -13,7 +13,7 @@ type arrayLazyAny struct { | ||||
| } | ||||
|  | ||||
| func (any *arrayLazyAny) ValueType() ValueType { | ||||
| 	return Array | ||||
| 	return ArrayValue | ||||
| } | ||||
|  | ||||
| func (any *arrayLazyAny) MustBeValid() Any { | ||||
| @@ -117,7 +117,7 @@ func (any *arrayLazyAny) Get(path ...interface{}) Any { | ||||
| 			arr := make([]Any, 0) | ||||
| 			iter.ReadArrayCB(func(iter *Iterator) bool { | ||||
| 				found := iter.readAny().Get(path[1:]...) | ||||
| 				if found.ValueType() != Invalid { | ||||
| 				if found.ValueType() != InvalidValue { | ||||
| 					arr = append(arr, found) | ||||
| 				} | ||||
| 				return true | ||||
| @@ -162,7 +162,7 @@ func wrapArray(val interface{}) *arrayAny { | ||||
| } | ||||
|  | ||||
| func (any *arrayAny) ValueType() ValueType { | ||||
| 	return Array | ||||
| 	return ArrayValue | ||||
| } | ||||
|  | ||||
| func (any *arrayAny) MustBeValid() Any { | ||||
| @@ -253,7 +253,7 @@ func (any *arrayAny) Get(path ...interface{}) Any { | ||||
| 			mappedAll := make([]Any, 0) | ||||
| 			for i := 0; i < any.val.Len(); i++ { | ||||
| 				mapped := Wrap(any.val.Index(i).Interface()).Get(path[1:]...) | ||||
| 				if mapped.ValueType() != Invalid { | ||||
| 				if mapped.ValueType() != InvalidValue { | ||||
| 					mappedAll = append(mappedAll, mapped) | ||||
| 				} | ||||
| 			} | ||||
|   | ||||
| @@ -61,7 +61,7 @@ func (any *trueAny) GetInterface() interface{} { | ||||
| } | ||||
|  | ||||
| func (any *trueAny) ValueType() ValueType { | ||||
| 	return Bool | ||||
| 	return BoolValue | ||||
| } | ||||
|  | ||||
| func (any *trueAny) MustBeValid() Any { | ||||
| @@ -129,7 +129,7 @@ func (any *falseAny) GetInterface() interface{} { | ||||
| } | ||||
|  | ||||
| func (any *falseAny) ValueType() ValueType { | ||||
| 	return Bool | ||||
| 	return BoolValue | ||||
| } | ||||
|  | ||||
| func (any *falseAny) MustBeValid() Any { | ||||
|   | ||||
| @@ -14,7 +14,7 @@ func (any *floatAny) Parse() *Iterator { | ||||
| } | ||||
|  | ||||
| func (any *floatAny) ValueType() ValueType { | ||||
| 	return Number | ||||
| 	return NumberValue | ||||
| } | ||||
|  | ||||
| func (any *floatAny) MustBeValid() Any { | ||||
|   | ||||
| @@ -14,7 +14,7 @@ func (any *int32Any) LastError() error { | ||||
| } | ||||
|  | ||||
| func (any *int32Any) ValueType() ValueType { | ||||
| 	return Number | ||||
| 	return NumberValue | ||||
| } | ||||
|  | ||||
| func (any *int32Any) MustBeValid() Any { | ||||
|   | ||||
| @@ -14,7 +14,7 @@ func (any *int64Any) LastError() error { | ||||
| } | ||||
|  | ||||
| func (any *int64Any) ValueType() ValueType { | ||||
| 	return Number | ||||
| 	return NumberValue | ||||
| } | ||||
|  | ||||
| func (any *int64Any) MustBeValid() Any { | ||||
|   | ||||
| @@ -16,7 +16,7 @@ func (any *invalidAny) LastError() error { | ||||
| } | ||||
|  | ||||
| func (any *invalidAny) ValueType() ValueType { | ||||
| 	return Invalid | ||||
| 	return InvalidValue | ||||
| } | ||||
|  | ||||
| func (any *invalidAny) MustBeValid() Any { | ||||
|   | ||||
| @@ -9,7 +9,7 @@ func (any *nilAny) LastError() error { | ||||
| } | ||||
|  | ||||
| func (any *nilAny) ValueType() ValueType { | ||||
| 	return Nil | ||||
| 	return NilValue | ||||
| } | ||||
|  | ||||
| func (any *nilAny) MustBeValid() Any { | ||||
|   | ||||
| @@ -10,7 +10,7 @@ type numberLazyAny struct { | ||||
| } | ||||
|  | ||||
| func (any *numberLazyAny) ValueType() ValueType { | ||||
| 	return Number | ||||
| 	return NumberValue | ||||
| } | ||||
|  | ||||
| func (any *numberLazyAny) MustBeValid() Any { | ||||
|   | ||||
| @@ -13,7 +13,7 @@ type objectLazyAny struct { | ||||
| } | ||||
|  | ||||
| func (any *objectLazyAny) ValueType() ValueType { | ||||
| 	return Object | ||||
| 	return ObjectValue | ||||
| } | ||||
|  | ||||
| func (any *objectLazyAny) MustBeValid() Any { | ||||
| @@ -91,7 +91,7 @@ func (any *objectLazyAny) Get(path ...interface{}) Any { | ||||
| 			defer any.cfg.ReturnIterator(iter) | ||||
| 			iter.ReadMapCB(func(iter *Iterator, field string) bool { | ||||
| 				mapped := locatePath(iter, path[1:]) | ||||
| 				if mapped.ValueType() != Invalid { | ||||
| 				if mapped.ValueType() != InvalidValue { | ||||
| 					mappedAll[field] = mapped | ||||
| 				} | ||||
| 				return true | ||||
| @@ -149,7 +149,7 @@ func wrapStruct(val interface{}) *objectAny { | ||||
| } | ||||
|  | ||||
| func (any *objectAny) ValueType() ValueType { | ||||
| 	return Object | ||||
| 	return ObjectValue | ||||
| } | ||||
|  | ||||
| func (any *objectAny) MustBeValid() Any { | ||||
| @@ -224,7 +224,7 @@ func (any *objectAny) Get(path ...interface{}) Any { | ||||
| 				field := any.val.Field(i) | ||||
| 				if field.CanInterface() { | ||||
| 					mapped := Wrap(field.Interface()).Get(path[1:]...) | ||||
| 					if mapped.ValueType() != Invalid { | ||||
| 					if mapped.ValueType() != InvalidValue { | ||||
| 						mappedAll[any.val.Type().Field(i).Name] = mapped | ||||
| 					} | ||||
| 				} | ||||
| @@ -268,7 +268,7 @@ func wrapMap(val interface{}) *mapAny { | ||||
| } | ||||
|  | ||||
| func (any *mapAny) ValueType() ValueType { | ||||
| 	return Object | ||||
| 	return ObjectValue | ||||
| } | ||||
|  | ||||
| func (any *mapAny) MustBeValid() Any { | ||||
| @@ -337,7 +337,7 @@ func (any *mapAny) Get(path ...interface{}) Any { | ||||
| 				keyAsStr := key.String() | ||||
| 				element := Wrap(any.val.MapIndex(key).Interface()) | ||||
| 				mapped := element.Get(path[1:]...) | ||||
| 				if mapped.ValueType() != Invalid { | ||||
| 				if mapped.ValueType() != InvalidValue { | ||||
| 					mappedAll[keyAsStr] = mapped | ||||
| 				} | ||||
| 			} | ||||
|   | ||||
| @@ -22,7 +22,7 @@ func (any *stringAny) Parse() *Iterator { | ||||
| } | ||||
|  | ||||
| func (any *stringAny) ValueType() ValueType { | ||||
| 	return String | ||||
| 	return StringValue | ||||
| } | ||||
|  | ||||
| func (any *stringAny) MustBeValid() Any { | ||||
|   | ||||
| @@ -14,7 +14,7 @@ func (any *uint32Any) LastError() error { | ||||
| } | ||||
|  | ||||
| func (any *uint32Any) ValueType() ValueType { | ||||
| 	return Number | ||||
| 	return NumberValue | ||||
| } | ||||
|  | ||||
| func (any *uint32Any) MustBeValid() Any { | ||||
|   | ||||
| @@ -14,7 +14,7 @@ func (any *uint64Any) LastError() error { | ||||
| } | ||||
|  | ||||
| func (any *uint64Any) ValueType() ValueType { | ||||
| 	return Number | ||||
| 	return NumberValue | ||||
| } | ||||
|  | ||||
| func (any *uint64Any) MustBeValid() Any { | ||||
|   | ||||
| @@ -88,7 +88,7 @@ func (cfg Config) Froze() API { | ||||
|  | ||||
| func (cfg *frozenConfig) useNumber() { | ||||
| 	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()) | ||||
| 		} else { | ||||
| 			*((*interface{})(ptr)) = iter.Read() | ||||
|   | ||||
| @@ -10,20 +10,20 @@ import ( | ||||
| type ValueType int | ||||
|  | ||||
| const ( | ||||
| 	// Invalid invalid JSON element | ||||
| 	Invalid ValueType = iota | ||||
| 	// String JSON element "string" | ||||
| 	String | ||||
| 	// Number JSON element 100 or 0.10 | ||||
| 	Number | ||||
| 	// Nil JSON element null | ||||
| 	Nil | ||||
| 	// Bool JSON element true or false | ||||
| 	Bool | ||||
| 	// Array JSON element [] | ||||
| 	Array | ||||
| 	// Object JSON element {} | ||||
| 	Object | ||||
| 	// InvalidValue invalid JSON element | ||||
| 	InvalidValue ValueType = iota | ||||
| 	// StringValue JSON element "string" | ||||
| 	StringValue | ||||
| 	// NumberValue JSON element 100 or 0.10 | ||||
| 	NumberValue | ||||
| 	// NilValue JSON element null | ||||
| 	NilValue | ||||
| 	// BoolValue JSON element true or false | ||||
| 	BoolValue | ||||
| 	// ArrayValue JSON element [] | ||||
| 	ArrayValue | ||||
| 	// ObjectValue JSON element {} | ||||
| 	ObjectValue | ||||
| ) | ||||
|  | ||||
| var hexDigits []byte | ||||
| @@ -45,25 +45,25 @@ func init() { | ||||
| 	} | ||||
| 	valueTypes = make([]ValueType, 256) | ||||
| 	for i := 0; i < len(valueTypes); i++ { | ||||
| 		valueTypes[i] = Invalid | ||||
| 		valueTypes[i] = InvalidValue | ||||
| 	} | ||||
| 	valueTypes['"'] = String | ||||
| 	valueTypes['-'] = Number | ||||
| 	valueTypes['0'] = Number | ||||
| 	valueTypes['1'] = Number | ||||
| 	valueTypes['2'] = Number | ||||
| 	valueTypes['3'] = Number | ||||
| 	valueTypes['4'] = Number | ||||
| 	valueTypes['5'] = Number | ||||
| 	valueTypes['6'] = Number | ||||
| 	valueTypes['7'] = Number | ||||
| 	valueTypes['8'] = Number | ||||
| 	valueTypes['9'] = Number | ||||
| 	valueTypes['t'] = Bool | ||||
| 	valueTypes['f'] = Bool | ||||
| 	valueTypes['n'] = Nil | ||||
| 	valueTypes['['] = Array | ||||
| 	valueTypes['{'] = Object | ||||
| 	valueTypes['"'] = StringValue | ||||
| 	valueTypes['-'] = NumberValue | ||||
| 	valueTypes['0'] = NumberValue | ||||
| 	valueTypes['1'] = NumberValue | ||||
| 	valueTypes['2'] = NumberValue | ||||
| 	valueTypes['3'] = NumberValue | ||||
| 	valueTypes['4'] = NumberValue | ||||
| 	valueTypes['5'] = NumberValue | ||||
| 	valueTypes['6'] = NumberValue | ||||
| 	valueTypes['7'] = NumberValue | ||||
| 	valueTypes['8'] = NumberValue | ||||
| 	valueTypes['9'] = NumberValue | ||||
| 	valueTypes['t'] = BoolValue | ||||
| 	valueTypes['f'] = BoolValue | ||||
| 	valueTypes['n'] = NilValue | ||||
| 	valueTypes['['] = ArrayValue | ||||
| 	valueTypes['{'] = ObjectValue | ||||
| } | ||||
|  | ||||
| // 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{} { | ||||
| 	valueType := iter.WhatIsNext() | ||||
| 	switch valueType { | ||||
| 	case String: | ||||
| 	case StringValue: | ||||
| 		return iter.ReadString() | ||||
| 	case Number: | ||||
| 	case NumberValue: | ||||
| 		if iter.cfg.configBeforeFrozen.UseNumber { | ||||
| 			return json.Number(iter.readNumberAsString()) | ||||
| 		} | ||||
| 		return iter.ReadFloat64() | ||||
| 	case Nil: | ||||
| 	case NilValue: | ||||
| 		iter.skipFourBytes('n', 'u', 'l', 'l') | ||||
| 		return nil | ||||
| 	case Bool: | ||||
| 	case BoolValue: | ||||
| 		return iter.ReadBool() | ||||
| 	case Array: | ||||
| 	case ArrayValue: | ||||
| 		arr := []interface{}{} | ||||
| 		iter.ReadArrayCB(func(iter *Iterator) bool { | ||||
| 			arr = append(arr, iter.Read()) | ||||
| 			return true | ||||
| 		}) | ||||
| 		return arr | ||||
| 	case Object: | ||||
| 	case ObjectValue: | ||||
| 		obj := map[string]interface{}{} | ||||
| 		iter.ReadMapCB(func(Iter *Iterator, field string) bool { | ||||
| 			obj[field] = iter.Read() | ||||
|   | ||||
| @@ -14,7 +14,7 @@ func (iter *Iterator) ReadNil() (ret bool) { | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| // ReadBool reads a json object as Bool | ||||
| // ReadBool reads a json object as BoolValue | ||||
| func (iter *Iterator) ReadBool() (ret bool) { | ||||
| 	c := iter.nextToken() | ||||
| 	if c == 't' { | ||||
|   | ||||
| @@ -436,7 +436,7 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||||
| 		return | ||||
| 	} | ||||
| 	switch iter.WhatIsNext() { | ||||
| 	case String: | ||||
| 	case StringValue: | ||||
| 		encoding := base64.StdEncoding | ||||
| 		src := iter.SkipAndReturnBytes() | ||||
| 		src = src[1 : len(src)-1] | ||||
| @@ -453,7 +453,7 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||||
| 			ptrSlice.Cap = dstSlice.Cap | ||||
| 			ptrSlice.Len = dstSlice.Len | ||||
| 		} | ||||
| 	case Array: | ||||
| 	case ArrayValue: | ||||
| 		codec.sliceDecoder.Decode(ptr, iter) | ||||
| 	default: | ||||
| 		iter.ReportError("base64Codec", "invalid input") | ||||
|   | ||||
| @@ -456,7 +456,7 @@ type skipObjectDecoder struct { | ||||
|  | ||||
| func (decoder *skipObjectDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||||
| 	valueType := iter.WhatIsNext() | ||||
| 	if valueType != Object && valueType != Nil { | ||||
| 	if valueType != ObjectValue && valueType != NilValue { | ||||
| 		iter.ReportError("skipObjectDecoder", "expect object or null") | ||||
| 		return | ||||
| 	} | ||||
|   | ||||
| @@ -9,10 +9,10 @@ import ( | ||||
| func Test_read_empty_array_as_any(t *testing.T) { | ||||
| 	should := require.New(t) | ||||
| 	any := Get([]byte("[]")) | ||||
| 	should.Equal(Array, any.Get().ValueType()) | ||||
| 	should.Equal(Invalid, any.Get(0.3).ValueType()) | ||||
| 	should.Equal(ArrayValue, any.Get().ValueType()) | ||||
| 	should.Equal(InvalidValue, any.Get(0.3).ValueType()) | ||||
| 	should.Equal(0, any.Size()) | ||||
| 	should.Equal(Array, any.ValueType()) | ||||
| 	should.Equal(ArrayValue, any.ValueType()) | ||||
| 	should.Nil(any.LastError()) | ||||
| 	should.Equal(0, any.ToInt()) | ||||
| 	should.Equal(int32(0), any.ToInt32()) | ||||
| @@ -101,7 +101,7 @@ func Test_array_wrapper_any_get_all(t *testing.T) { | ||||
| 		{5, 6}, | ||||
| 	}) | ||||
| 	should.Equal("[1,3,5]", any.Get('*', 0).ToString()) | ||||
| 	should.Equal(Array, any.ValueType()) | ||||
| 	should.Equal(ArrayValue, any.ValueType()) | ||||
| 	should.True(any.ToBool()) | ||||
| 	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) { | ||||
| 	should := require.New(t) | ||||
| 	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.Equal(Invalid, any.Get("1").ValueType()) | ||||
| 	should.Equal(InvalidValue, any.Get("1").ValueType()) | ||||
| 	should.NotNil(any.Get("1").LastError()) | ||||
| } | ||||
|  | ||||
| func Test_invalid_array(t *testing.T) { | ||||
| 	should := require.New(t) | ||||
| 	any := Get([]byte("["), 0) | ||||
| 	should.Equal(Invalid, any.ValueType()) | ||||
| 	should.Equal(InvalidValue, any.ValueType()) | ||||
| } | ||||
|   | ||||
| @@ -53,12 +53,12 @@ func Test_write_bool_to_stream(t *testing.T) { | ||||
| 	stream := NewStream(ConfigDefault, nil, 32) | ||||
| 	any.WriteTo(stream) | ||||
| 	should.Equal("true", string(stream.Buffer())) | ||||
| 	should.Equal(any.ValueType(), Bool) | ||||
| 	should.Equal(any.ValueType(), BoolValue) | ||||
|  | ||||
| 	any = Get([]byte("false")) | ||||
| 	stream = NewStream(ConfigDefault, nil, 32) | ||||
| 	any.WriteTo(stream) | ||||
| 	should.Equal("false", string(stream.Buffer())) | ||||
|  | ||||
| 	should.Equal(any.ValueType(), Bool) | ||||
| 	should.Equal(any.ValueType(), BoolValue) | ||||
| } | ||||
|   | ||||
| @@ -96,7 +96,7 @@ func Test_read_float_to_any(t *testing.T) { | ||||
| 	should.Equal(uint(0), any2.ToUint()) | ||||
| 	should.Equal(uint32(0), any2.ToUint32()) | ||||
| 	should.Equal(uint64(0), any2.ToUint64()) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
|  | ||||
| 	should.Equal("1.23E+01", any.ToString()) | ||||
| } | ||||
|   | ||||
| @@ -123,7 +123,7 @@ func Test_read_int64_to_any(t *testing.T) { | ||||
| 	should.Equal(float64(12345), any.ToFloat64()) | ||||
| 	should.Equal("12345", any.ToString()) | ||||
| 	should.Equal(true, any.ToBool()) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	stream := NewStream(ConfigDefault, nil, 32) | ||||
| 	any.WriteTo(stream) | ||||
| 	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("12345", any.ToString()) | ||||
| 	should.Equal(true, any.ToBool()) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	stream := NewStream(ConfigDefault, nil, 32) | ||||
| 	any.WriteTo(stream) | ||||
| 	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("12345", any.ToString()) | ||||
| 	should.Equal(true, any.ToBool()) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	stream := NewStream(ConfigDefault, nil, 32) | ||||
| 	any.WriteTo(stream) | ||||
| 	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("12345", any.ToString()) | ||||
| 	should.Equal(true, any.ToBool()) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	stream := NewStream(ConfigDefault, nil, 32) | ||||
| 	any.WriteTo(stream) | ||||
| 	should.Equal("12345", string(stream.Buffer())) | ||||
| @@ -193,5 +193,5 @@ func Test_int_lazy_any_get(t *testing.T) { | ||||
| 	any := Get([]byte("1234")) | ||||
| 	// panic!! | ||||
| 	//should.Equal(any.LastError(), io.EOF) | ||||
| 	should.Equal(Invalid, any.Get(1, "2").ValueType()) | ||||
| 	should.Equal(InvalidValue, any.Get(1, "2").ValueType()) | ||||
| } | ||||
|   | ||||
| @@ -20,7 +20,7 @@ func Test_read_object_as_any(t *testing.T) { | ||||
| 	should.Equal(2, any.Size()) | ||||
| 	should.True(any.ToBool()) | ||||
| 	should.Equal(0, any.ToInt()) | ||||
| 	should.Equal(Object, any.ValueType()) | ||||
| 	should.Equal(ObjectValue, any.ValueType()) | ||||
| 	should.Nil(any.LastError()) | ||||
| 	obj := struct { | ||||
| 		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) { | ||||
| 	should := require.New(t) | ||||
| 	any := Get([]byte(`{}`)) | ||||
| 	should.Equal(Invalid, any.Get("a", "stream", "c").ValueType()) | ||||
| 	should.Equal(Invalid, any.Get(1).ValueType()) | ||||
| 	should.Equal(InvalidValue, any.Get("a", "stream", "c").ValueType()) | ||||
| 	should.Equal(InvalidValue, any.Get(1).ValueType()) | ||||
| } | ||||
|  | ||||
| func Test_wrap_map_and_convert_to_any(t *testing.T) { | ||||
|   | ||||
| @@ -25,7 +25,7 @@ func Test_missing_array_end(t *testing.T) { | ||||
| func Test_invalid_any(t *testing.T) { | ||||
| 	should := require.New(t) | ||||
| 	any := Get([]byte("[]")) | ||||
| 	should.Equal(Invalid, any.Get(0.3).ValueType()) | ||||
| 	should.Equal(InvalidValue, any.Get(0.3).ValueType()) | ||||
| 	// is nil correct ? | ||||
| 	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("", 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) { | ||||
|   | ||||
| @@ -15,80 +15,80 @@ func Test_wrap_and_valuetype_everything(t *testing.T) { | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
|  | ||||
| 	any = Wrap(int8(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	//  get interface is not int8 interface | ||||
| 	// i = int8(10) | ||||
| 	// should.Equal(i, any.GetInterface()) | ||||
|  | ||||
| 	any = Wrap(int16(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	//i = int16(10) | ||||
| 	//should.Equal(i, any.GetInterface()) | ||||
|  | ||||
| 	any = Wrap(int32(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = int32(10) | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
| 	any = Wrap(int64(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = int64(10) | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
|  | ||||
| 	any = Wrap(uint(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	// not equal | ||||
| 	//i = uint(10) | ||||
| 	//should.Equal(i, any.GetInterface()) | ||||
| 	any = Wrap(uint8(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	// not equal | ||||
| 	// i = uint8(10) | ||||
| 	// should.Equal(i, any.GetInterface()) | ||||
| 	any = Wrap(uint16(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	any = Wrap(uint32(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = uint32(10) | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
| 	any = Wrap(uint64(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = uint64(10) | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
|  | ||||
| 	any = Wrap(float32(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	// not equal | ||||
| 	//i = float32(10) | ||||
| 	//should.Equal(i, any.GetInterface()) | ||||
| 	any = Wrap(float64(10)) | ||||
| 	should.Equal(any.ValueType(), Number) | ||||
| 	should.Equal(any.ValueType(), NumberValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = float64(10) | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
|  | ||||
| 	any = Wrap(true) | ||||
| 	should.Equal(any.ValueType(), Bool) | ||||
| 	should.Equal(any.ValueType(), BoolValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = true | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
| 	any = Wrap(false) | ||||
| 	should.Equal(any.ValueType(), Bool) | ||||
| 	should.Equal(any.ValueType(), BoolValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = false | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
|  | ||||
| 	any = Wrap(nil) | ||||
| 	should.Equal(any.ValueType(), Nil) | ||||
| 	should.Equal(any.ValueType(), NilValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = nil | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
| @@ -99,13 +99,13 @@ func Test_wrap_and_valuetype_everything(t *testing.T) { | ||||
| 	should.Equal(any.LastError(), nil) | ||||
|  | ||||
| 	any = Wrap(struct{ age int }{age: 1}) | ||||
| 	should.Equal(any.ValueType(), Object) | ||||
| 	should.Equal(any.ValueType(), ObjectValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = struct{ age int }{age: 1} | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
|  | ||||
| 	any = Wrap(map[string]interface{}{"abc": 1}) | ||||
| 	should.Equal(any.ValueType(), Object) | ||||
| 	should.Equal(any.ValueType(), ObjectValue) | ||||
| 	should.Equal(any.LastError(), nil) | ||||
| 	i = map[string]interface{}{"abc": 1} | ||||
| 	should.Equal(i, any.GetInterface()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user