Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit ac3b3cd

Browse files
committed
test []interface{}
1 parent 9c35863 commit ac3b3cd

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

jsoniter_customize_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"testing"
88
"time"
99
"unsafe"
10+
"fmt"
11+
"reflect"
1012
)
1113

1214
func Test_customize_type_decoder(t *testing.T) {
@@ -285,3 +287,23 @@ func Test_marshal_json_with_time(t *testing.T) {
285287
should.Nil(Unmarshal([]byte(`{"TF1":{"F1":"fake","F2":"fake"}}`), &obj))
286288
should.NotNil(obj.TF1.F2)
287289
}
290+
291+
func Test_unmarshal_empty_interface_as_int64(t *testing.T) {
292+
var obj interface{}
293+
RegisterTypeDecoderFunc("interface {}", func(ptr unsafe.Pointer, iter *Iterator) {
294+
switch iter.WhatIsNext() {
295+
case NumberValue:
296+
*(*interface{})(ptr) = iter.ReadInt64()
297+
default:
298+
*(*interface{})(ptr) = iter.Read()
299+
}
300+
})
301+
should := require.New(t)
302+
Unmarshal([]byte("100"), &obj)
303+
should.Equal(int64(100), obj)
304+
Unmarshal([]byte(`"hello"`), &obj)
305+
should.Equal("hello", obj)
306+
var arr []interface{}
307+
Unmarshal([]byte("[100]"), &arr)
308+
should.Equal(int64(100), arr[0])
309+
}

jsoniter_invalid_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,18 @@ func Test_invalid_float(t *testing.T) {
9898
})
9999
}
100100
}
101+
102+
func Test_chan(t *testing.T) {
103+
t.Skip("do not support chan")
104+
105+
type TestObject struct {
106+
MyChan chan bool
107+
MyField int
108+
}
109+
110+
should := require.New(t)
111+
obj := TestObject{}
112+
str, err := json.Marshal(obj)
113+
should.Nil(err)
114+
should.Equal(``, str)
115+
}

0 commit comments

Comments
 (0)