Skip to content

Commit 761ce8c

Browse files
committed
consolidate more tests
1 parent c3b6c1e commit 761ce8c

18 files changed

+237
-276
lines changed

jsoniter_any_array_test.go renamed to any_tests/jsoniter_any_array_test.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
package jsoniter
1+
package any_tests
22

33
import (
44
"testing"
55

66
"github.com/stretchr/testify/require"
7+
"github.com/json-iterator/go"
78
)
89

910
func Test_read_empty_array_as_any(t *testing.T) {
1011
should := require.New(t)
11-
any := Get([]byte("[]"))
12-
should.Equal(ArrayValue, any.Get().ValueType())
13-
should.Equal(InvalidValue, any.Get(0.3).ValueType())
12+
any := jsoniter.Get([]byte("[]"))
13+
should.Equal(jsoniter.ArrayValue, any.Get().ValueType())
14+
should.Equal(jsoniter.InvalidValue, any.Get(0.3).ValueType())
1415
should.Equal(0, any.Size())
15-
should.Equal(ArrayValue, any.ValueType())
16+
should.Equal(jsoniter.ArrayValue, any.ValueType())
1617
should.Nil(any.LastError())
1718
should.Equal(0, any.ToInt())
1819
should.Equal(int32(0), any.ToInt32())
@@ -26,19 +27,19 @@ func Test_read_empty_array_as_any(t *testing.T) {
2627

2728
func Test_read_one_element_array_as_any(t *testing.T) {
2829
should := require.New(t)
29-
any := Get([]byte("[1]"))
30+
any := jsoniter.Get([]byte("[1]"))
3031
should.Equal(1, any.Size())
3132
}
3233

3334
func Test_read_two_element_array_as_any(t *testing.T) {
3435
should := require.New(t)
35-
any := Get([]byte("[1,2]"))
36+
any := jsoniter.Get([]byte("[1,2]"))
3637
should.Equal(1, any.Get(0).ToInt())
3738
should.Equal(2, any.Size())
3839
should.True(any.ToBool())
3940
should.Equal(1, any.ToInt())
4041
should.Equal([]interface{}{float64(1), float64(2)}, any.GetInterface())
41-
stream := NewStream(ConfigDefault, nil, 32)
42+
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
4243
any.WriteTo(stream)
4344
should.Equal("[1,2]", string(stream.Buffer()))
4445
arr := []int{}
@@ -48,8 +49,8 @@ func Test_read_two_element_array_as_any(t *testing.T) {
4849

4950
func Test_wrap_array_and_convert_to_any(t *testing.T) {
5051
should := require.New(t)
51-
any := Wrap([]int{1, 2, 3})
52-
any2 := Wrap([]int{})
52+
any := jsoniter.Wrap([]int{1, 2, 3})
53+
any2 := jsoniter.Wrap([]int{})
5354

5455
should.Equal("[1,2,3]", any.ToString())
5556
should.True(any.ToBool())
@@ -80,43 +81,43 @@ func Test_wrap_array_and_convert_to_any(t *testing.T) {
8081

8182
func Test_array_lazy_any_get(t *testing.T) {
8283
should := require.New(t)
83-
any := Get([]byte("[1,[2,3],4]"))
84+
any := jsoniter.Get([]byte("[1,[2,3],4]"))
8485
should.Equal(3, any.Get(1, 1).ToInt())
8586
should.Equal("[1,[2,3],4]", any.ToString())
8687
}
8788

8889
func Test_array_lazy_any_get_all(t *testing.T) {
8990
should := require.New(t)
90-
any := Get([]byte("[[1],[2],[3,4]]"))
91+
any := jsoniter.Get([]byte("[[1],[2],[3,4]]"))
9192
should.Equal("[1,2,3]", any.Get('*', 0).ToString())
92-
any = Get([]byte("[[[1],[2],[3,4]]]"), 0, '*', 0)
93+
any = jsoniter.Get([]byte("[[[1],[2],[3,4]]]"), 0, '*', 0)
9394
should.Equal("[1,2,3]", any.ToString())
9495
}
9596

9697
func Test_array_wrapper_any_get_all(t *testing.T) {
9798
should := require.New(t)
98-
any := wrapArray([][]int{
99+
any := jsoniter.Wrap([][]int{
99100
{1, 2},
100101
{3, 4},
101102
{5, 6},
102103
})
103104
should.Equal("[1,3,5]", any.Get('*', 0).ToString())
104-
should.Equal(ArrayValue, any.ValueType())
105+
should.Equal(jsoniter.ArrayValue, any.ValueType())
105106
should.True(any.ToBool())
106107
should.Equal(1, any.Get(0, 0).ToInt())
107108
}
108109

109110
func Test_array_lazy_any_get_invalid(t *testing.T) {
110111
should := require.New(t)
111-
any := Get([]byte("[]"))
112-
should.Equal(InvalidValue, any.Get(1, 1).ValueType())
112+
any := jsoniter.Get([]byte("[]"))
113+
should.Equal(jsoniter.InvalidValue, any.Get(1, 1).ValueType())
113114
should.NotNil(any.Get(1, 1).LastError())
114-
should.Equal(InvalidValue, any.Get("1").ValueType())
115+
should.Equal(jsoniter.InvalidValue, any.Get("1").ValueType())
115116
should.NotNil(any.Get("1").LastError())
116117
}
117118

118119
func Test_invalid_array(t *testing.T) {
119120
should := require.New(t)
120-
any := Get([]byte("["), 0)
121-
should.Equal(InvalidValue, any.ValueType())
121+
any := jsoniter.Get([]byte("["), 0)
122+
should.Equal(jsoniter.InvalidValue, any.ValueType())
122123
}

jsoniter_any_bool_test.go renamed to any_tests/jsoniter_any_bool_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package jsoniter
1+
package any_tests
22

33
import (
44
"fmt"
55
"testing"
66

77
"github.com/stretchr/testify/require"
8+
"github.com/json-iterator/go"
89
)
910

1011
var boolConvertMap = map[string]bool{
@@ -35,9 +36,9 @@ var boolConvertMap = map[string]bool{
3536
func Test_read_bool_as_any(t *testing.T) {
3637
should := require.New(t)
3738

38-
var any Any
39+
var any jsoniter.Any
3940
for k, v := range boolConvertMap {
40-
any = Get([]byte(k))
41+
any = jsoniter.Get([]byte(k))
4142
if v {
4243
should.True(any.ToBool(), fmt.Sprintf("origin val is %v", k))
4344
} else {
@@ -49,16 +50,16 @@ func Test_read_bool_as_any(t *testing.T) {
4950

5051
func Test_write_bool_to_stream(t *testing.T) {
5152
should := require.New(t)
52-
any := Get([]byte("true"))
53-
stream := NewStream(ConfigDefault, nil, 32)
53+
any := jsoniter.Get([]byte("true"))
54+
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
5455
any.WriteTo(stream)
5556
should.Equal("true", string(stream.Buffer()))
56-
should.Equal(any.ValueType(), BoolValue)
57+
should.Equal(any.ValueType(), jsoniter.BoolValue)
5758

58-
any = Get([]byte("false"))
59-
stream = NewStream(ConfigDefault, nil, 32)
59+
any = jsoniter.Get([]byte("false"))
60+
stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
6061
any.WriteTo(stream)
6162
should.Equal("false", string(stream.Buffer()))
6263

63-
should.Equal(any.ValueType(), BoolValue)
64+
should.Equal(any.ValueType(), jsoniter.BoolValue)
6465
}

jsoniter_any_float_test.go renamed to any_tests/jsoniter_any_float_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package jsoniter
1+
package any_tests
22

33
import (
44
"testing"
55

66
"github.com/stretchr/testify/require"
7+
"github.com/json-iterator/go"
78
)
89

910
var floatConvertMap = map[string]float64{
@@ -67,22 +68,22 @@ var floatConvertMap = map[string]float64{
6768
func Test_read_any_to_float(t *testing.T) {
6869
should := require.New(t)
6970
for k, v := range floatConvertMap {
70-
any := Get([]byte(k))
71+
any := jsoniter.Get([]byte(k))
7172
should.Equal(float64(v), any.ToFloat64(), "the original val is "+k)
7273
}
7374

7475
for k, v := range floatConvertMap {
75-
any := Get([]byte(k))
76+
any := jsoniter.Get([]byte(k))
7677
should.Equal(float32(v), any.ToFloat32(), "the original val is "+k)
7778
}
7879
}
7980

8081
func Test_read_float_to_any(t *testing.T) {
8182
should := require.New(t)
82-
any := WrapFloat64(12.3)
83+
any := jsoniter.WrapFloat64(12.3)
8384
anyFloat64 := float64(12.3)
8485
//negaAnyFloat64 := float64(-1.1)
85-
any2 := WrapFloat64(-1.1)
86+
any2 := jsoniter.WrapFloat64(-1.1)
8687
should.Equal(float64(12.3), any.ToFloat64())
8788
//should.Equal("12.3", any.ToString())
8889
should.True(any.ToBool())
@@ -96,7 +97,7 @@ func Test_read_float_to_any(t *testing.T) {
9697
should.Equal(uint(0), any2.ToUint())
9798
should.Equal(uint32(0), any2.ToUint32())
9899
should.Equal(uint64(0), any2.ToUint64())
99-
should.Equal(any.ValueType(), NumberValue)
100+
should.Equal(any.ValueType(), jsoniter.NumberValue)
100101

101102
should.Equal("1.23E+01", any.ToString())
102103
}

jsoniter_any_int_test.go renamed to any_tests/jsoniter_any_int_test.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package jsoniter
1+
package any_tests
22

33
import (
44
"fmt"
55
"testing"
66

77
"github.com/stretchr/testify/require"
8+
"github.com/json-iterator/go"
89
)
910

1011
var intConvertMap = map[string]int{
@@ -41,19 +42,19 @@ func Test_read_any_to_int(t *testing.T) {
4142

4243
// int
4344
for k, v := range intConvertMap {
44-
any := Get([]byte(k))
45+
any := jsoniter.Get([]byte(k))
4546
should.Equal(v, any.ToInt(), fmt.Sprintf("origin val %v", k))
4647
}
4748

4849
// int32
4950
for k, v := range intConvertMap {
50-
any := Get([]byte(k))
51+
any := jsoniter.Get([]byte(k))
5152
should.Equal(int32(v), any.ToInt32(), fmt.Sprintf("original val is %v", k))
5253
}
5354

5455
// int64
5556
for k, v := range intConvertMap {
56-
any := Get([]byte(k))
57+
any := jsoniter.Get([]byte(k))
5758
should.Equal(int64(v), any.ToInt64(), fmt.Sprintf("original val is %v", k))
5859
}
5960

@@ -94,25 +95,25 @@ func Test_read_any_to_uint(t *testing.T) {
9495
should := require.New(t)
9596

9697
for k, v := range uintConvertMap {
97-
any := Get([]byte(k))
98+
any := jsoniter.Get([]byte(k))
9899
should.Equal(uint64(v), any.ToUint64(), fmt.Sprintf("origin val %v", k))
99100
}
100101

101102
for k, v := range uintConvertMap {
102-
any := Get([]byte(k))
103+
any := jsoniter.Get([]byte(k))
103104
should.Equal(uint32(v), any.ToUint32(), fmt.Sprintf("origin val %v", k))
104105
}
105106

106107
for k, v := range uintConvertMap {
107-
any := Get([]byte(k))
108+
any := jsoniter.Get([]byte(k))
108109
should.Equal(uint(v), any.ToUint(), fmt.Sprintf("origin val %v", k))
109110
}
110111

111112
}
112113

113114
func Test_read_int64_to_any(t *testing.T) {
114115
should := require.New(t)
115-
any := WrapInt64(12345)
116+
any := jsoniter.WrapInt64(12345)
116117
should.Equal(12345, any.ToInt())
117118
should.Equal(int32(12345), any.ToInt32())
118119
should.Equal(int64(12345), any.ToInt64())
@@ -123,14 +124,14 @@ func Test_read_int64_to_any(t *testing.T) {
123124
should.Equal(float64(12345), any.ToFloat64())
124125
should.Equal("12345", any.ToString())
125126
should.Equal(true, any.ToBool())
126-
should.Equal(any.ValueType(), NumberValue)
127-
stream := NewStream(ConfigDefault, nil, 32)
127+
should.Equal(any.ValueType(), jsoniter.NumberValue)
128+
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
128129
any.WriteTo(stream)
129130
should.Equal("12345", string(stream.Buffer()))
130131
}
131132
func Test_read_int32_to_any(t *testing.T) {
132133
should := require.New(t)
133-
any := WrapInt32(12345)
134+
any := jsoniter.WrapInt32(12345)
134135
should.Equal(12345, any.ToInt())
135136
should.Equal(int32(12345), any.ToInt32())
136137
should.Equal(int64(12345), any.ToInt64())
@@ -141,15 +142,15 @@ func Test_read_int32_to_any(t *testing.T) {
141142
should.Equal(float64(12345), any.ToFloat64())
142143
should.Equal("12345", any.ToString())
143144
should.Equal(true, any.ToBool())
144-
should.Equal(any.ValueType(), NumberValue)
145-
stream := NewStream(ConfigDefault, nil, 32)
145+
should.Equal(any.ValueType(), jsoniter.NumberValue)
146+
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
146147
any.WriteTo(stream)
147148
should.Equal("12345", string(stream.Buffer()))
148149
}
149150

150151
func Test_read_uint32_to_any(t *testing.T) {
151152
should := require.New(t)
152-
any := WrapUint32(12345)
153+
any := jsoniter.WrapUint32(12345)
153154
should.Equal(12345, any.ToInt())
154155
should.Equal(int32(12345), any.ToInt32())
155156
should.Equal(int64(12345), any.ToInt64())
@@ -160,15 +161,15 @@ func Test_read_uint32_to_any(t *testing.T) {
160161
should.Equal(float64(12345), any.ToFloat64())
161162
should.Equal("12345", any.ToString())
162163
should.Equal(true, any.ToBool())
163-
should.Equal(any.ValueType(), NumberValue)
164-
stream := NewStream(ConfigDefault, nil, 32)
164+
should.Equal(any.ValueType(), jsoniter.NumberValue)
165+
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
165166
any.WriteTo(stream)
166167
should.Equal("12345", string(stream.Buffer()))
167168
}
168169

169170
func Test_read_uint64_to_any(t *testing.T) {
170171
should := require.New(t)
171-
any := WrapUint64(12345)
172+
any := jsoniter.WrapUint64(12345)
172173
should.Equal(12345, any.ToInt())
173174
should.Equal(int32(12345), any.ToInt32())
174175
should.Equal(int64(12345), any.ToInt64())
@@ -179,19 +180,19 @@ func Test_read_uint64_to_any(t *testing.T) {
179180
should.Equal(float64(12345), any.ToFloat64())
180181
should.Equal("12345", any.ToString())
181182
should.Equal(true, any.ToBool())
182-
should.Equal(any.ValueType(), NumberValue)
183-
stream := NewStream(ConfigDefault, nil, 32)
183+
should.Equal(any.ValueType(), jsoniter.NumberValue)
184+
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
184185
any.WriteTo(stream)
185186
should.Equal("12345", string(stream.Buffer()))
186-
stream = NewStream(ConfigDefault, nil, 32)
187+
stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 32)
187188
stream.WriteUint(uint(123))
188189
should.Equal("123", string(stream.Buffer()))
189190
}
190191

191192
func Test_int_lazy_any_get(t *testing.T) {
192193
should := require.New(t)
193-
any := Get([]byte("1234"))
194+
any := jsoniter.Get([]byte("1234"))
194195
// panic!!
195196
//should.Equal(any.LastError(), io.EOF)
196-
should.Equal(InvalidValue, any.Get(1, "2").ValueType())
197+
should.Equal(jsoniter.InvalidValue, any.Get(1, "2").ValueType())
197198
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
package jsoniter
1+
package any_tests
22

33
import (
44
"github.com/stretchr/testify/require"
55
"testing"
6+
"github.com/json-iterator/go"
67
)
78

89
func Test_wrap_map(t *testing.T) {
910
should := require.New(t)
10-
any := Wrap(map[string]string{"Field1": "hello"})
11+
any := jsoniter.Wrap(map[string]string{"Field1": "hello"})
1112
should.Equal("hello", any.Get("Field1").ToString())
12-
any = Wrap(map[string]string{"Field1": "hello"})
13+
any = jsoniter.Wrap(map[string]string{"Field1": "hello"})
1314
should.Equal(1, any.Size())
1415
}

jsoniter_any_null_test.go renamed to any_tests/jsoniter_any_null_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
package jsoniter
1+
package any_tests
22

33
import (
44
"github.com/stretchr/testify/require"
55
"testing"
6+
"github.com/json-iterator/go"
67
)
78

89
func Test_read_null_as_any(t *testing.T) {
910
should := require.New(t)
10-
any := Get([]byte(`null`))
11+
any := jsoniter.Get([]byte(`null`))
1112
should.Equal(0, any.ToInt())
1213
should.Equal(float64(0), any.ToFloat64())
1314
should.Equal("", any.ToString())

0 commit comments

Comments
 (0)