1 package any_tests
2
3 import (
4 "testing"
5
6 "github.com/json-iterator/go"
7 "github.com/stretchr/testify/require"
8 )
9
10 func Test_wrap_and_valuetype_everything(t *testing.T) {
11 should := require.New(t)
12 var i interface{}
13 any := jsoniter.Get([]byte("123"))
14
15 i = float64(123)
16 should.Equal(i, any.GetInterface())
17
18 any = jsoniter.Wrap(int8(10))
19 should.Equal(any.ValueType(), jsoniter.NumberValue)
20 should.Equal(any.LastError(), nil)
21
22
23
24
25 any = jsoniter.Wrap(int16(10))
26 should.Equal(any.ValueType(), jsoniter.NumberValue)
27 should.Equal(any.LastError(), nil)
28
29
30
31 any = jsoniter.Wrap(int32(10))
32 should.Equal(any.ValueType(), jsoniter.NumberValue)
33 should.Equal(any.LastError(), nil)
34 i = int32(10)
35 should.Equal(i, any.GetInterface())
36 any = jsoniter.Wrap(int64(10))
37 should.Equal(any.ValueType(), jsoniter.NumberValue)
38 should.Equal(any.LastError(), nil)
39 i = int64(10)
40 should.Equal(i, any.GetInterface())
41
42 any = jsoniter.Wrap(uint(10))
43 should.Equal(any.ValueType(), jsoniter.NumberValue)
44 should.Equal(any.LastError(), nil)
45
46
47
48 any = jsoniter.Wrap(uint8(10))
49 should.Equal(any.ValueType(), jsoniter.NumberValue)
50 should.Equal(any.LastError(), nil)
51
52
53
54 any = jsoniter.Wrap(uint16(10))
55 should.Equal(any.ValueType(), jsoniter.NumberValue)
56 should.Equal(any.LastError(), nil)
57 any = jsoniter.Wrap(uint32(10))
58 should.Equal(any.ValueType(), jsoniter.NumberValue)
59 should.Equal(any.LastError(), nil)
60 i = uint32(10)
61 should.Equal(i, any.GetInterface())
62 any = jsoniter.Wrap(uint64(10))
63 should.Equal(any.ValueType(), jsoniter.NumberValue)
64 should.Equal(any.LastError(), nil)
65 i = uint64(10)
66 should.Equal(i, any.GetInterface())
67
68 any = jsoniter.Wrap(float32(10))
69 should.Equal(any.ValueType(), jsoniter.NumberValue)
70 should.Equal(any.LastError(), nil)
71
72
73
74 any = jsoniter.Wrap(float64(10))
75 should.Equal(any.ValueType(), jsoniter.NumberValue)
76 should.Equal(any.LastError(), nil)
77 i = float64(10)
78 should.Equal(i, any.GetInterface())
79
80 any = jsoniter.Wrap(true)
81 should.Equal(any.ValueType(), jsoniter.BoolValue)
82 should.Equal(any.LastError(), nil)
83 i = true
84 should.Equal(i, any.GetInterface())
85 any = jsoniter.Wrap(false)
86 should.Equal(any.ValueType(), jsoniter.BoolValue)
87 should.Equal(any.LastError(), nil)
88 i = false
89 should.Equal(i, any.GetInterface())
90
91 any = jsoniter.Wrap(nil)
92 should.Equal(any.ValueType(), jsoniter.NilValue)
93 should.Equal(any.LastError(), nil)
94 i = nil
95 should.Equal(i, any.GetInterface())
96
97 stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
98 any.WriteTo(stream)
99 should.Equal("null", string(stream.Buffer()))
100 should.Equal(any.LastError(), nil)
101
102 any = jsoniter.Wrap(struct{ age int }{age: 1})
103 should.Equal(any.ValueType(), jsoniter.ObjectValue)
104 should.Equal(any.LastError(), nil)
105 i = struct{ age int }{age: 1}
106 should.Equal(i, any.GetInterface())
107
108 any = jsoniter.Wrap(map[string]interface{}{"abc": 1})
109 should.Equal(any.ValueType(), jsoniter.ObjectValue)
110 should.Equal(any.LastError(), nil)
111 i = map[string]interface{}{"abc": 1}
112 should.Equal(i, any.GetInterface())
113
114 any = jsoniter.Wrap("abc")
115 i = "abc"
116 should.Equal(i, any.GetInterface())
117 should.Equal(nil, any.LastError())
118
119 }
120
View as plain text