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