You've already forked json-iterator
							
							
				mirror of
				https://github.com/json-iterator/go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	test []interface{}
This commit is contained in:
		| @@ -7,6 +7,8 @@ import ( | |||||||
| 	"testing" | 	"testing" | ||||||
| 	"time" | 	"time" | ||||||
| 	"unsafe" | 	"unsafe" | ||||||
|  | 	"fmt" | ||||||
|  | 	"reflect" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func Test_customize_type_decoder(t *testing.T) { | func Test_customize_type_decoder(t *testing.T) { | ||||||
| @@ -285,3 +287,23 @@ func Test_marshal_json_with_time(t *testing.T) { | |||||||
| 	should.Nil(Unmarshal([]byte(`{"TF1":{"F1":"fake","F2":"fake"}}`), &obj)) | 	should.Nil(Unmarshal([]byte(`{"TF1":{"F1":"fake","F2":"fake"}}`), &obj)) | ||||||
| 	should.NotNil(obj.TF1.F2) | 	should.NotNil(obj.TF1.F2) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func Test_unmarshal_empty_interface_as_int64(t *testing.T) { | ||||||
|  | 	var obj interface{} | ||||||
|  | 	RegisterTypeDecoderFunc("interface {}", func(ptr unsafe.Pointer, iter *Iterator) { | ||||||
|  | 		switch iter.WhatIsNext() { | ||||||
|  | 		case NumberValue: | ||||||
|  | 			*(*interface{})(ptr) = iter.ReadInt64() | ||||||
|  | 		default: | ||||||
|  | 			*(*interface{})(ptr) = iter.Read() | ||||||
|  | 		} | ||||||
|  | 	}) | ||||||
|  | 	should := require.New(t) | ||||||
|  | 	Unmarshal([]byte("100"), &obj) | ||||||
|  | 	should.Equal(int64(100), obj) | ||||||
|  | 	Unmarshal([]byte(`"hello"`), &obj) | ||||||
|  | 	should.Equal("hello", obj) | ||||||
|  | 	var arr []interface{} | ||||||
|  | 	Unmarshal([]byte("[100]"), &arr) | ||||||
|  | 	should.Equal(int64(100), arr[0]) | ||||||
|  | } | ||||||
|   | |||||||
| @@ -98,3 +98,18 @@ func Test_invalid_float(t *testing.T) { | |||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func Test_chan(t *testing.T) { | ||||||
|  | 	t.Skip("do not support chan") | ||||||
|  |  | ||||||
|  | 	type TestObject struct { | ||||||
|  | 		MyChan chan bool | ||||||
|  | 		MyField int | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	should := require.New(t) | ||||||
|  | 	obj := TestObject{} | ||||||
|  | 	str, err := json.Marshal(obj) | ||||||
|  | 	should.Nil(err) | ||||||
|  | 	should.Equal(``, str) | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user