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

Commit e3bc511

Browse files
committed
consolidate more tests
1 parent 8fa357a commit e3bc511

File tree

9 files changed

+99
-258
lines changed

9 files changed

+99
-258
lines changed

any_tests/jsoniter_any_map_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ func Test_wrap_map(t *testing.T) {
1313
any = jsoniter.Wrap(map[string]string{"Field1": "hello"})
1414
should.Equal(1, any.Size())
1515
}
16+
17+
func Test_map_wrapper_any_get_all(t *testing.T) {
18+
should := require.New(t)
19+
any := jsoniter.Wrap(map[string][]int{"Field1": {1, 2}})
20+
should.Equal(`{"Field1":1}`, any.Get('*', 0).ToString())
21+
should.Contains(any.Keys(), "Field1")
22+
23+
// map write to
24+
stream := jsoniter.NewStream(jsoniter.ConfigDefault, nil, 0)
25+
any.WriteTo(stream)
26+
// TODO cannot pass
27+
//should.Equal(string(stream.buf), "")
28+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package jsoniter
1+
package test
22

33
import (
44
"encoding/json"
55
"io/ioutil"
66
"os"
77
"testing"
8+
"github.com/json-iterator/go"
89
)
910

1011
//func Test_large_file(t *testing.T) {
@@ -127,9 +128,9 @@ func Benchmark_jsoniter_large_file(b *testing.B) {
127128
b.ReportAllocs()
128129
for n := 0; n < b.N; n++ {
129130
file, _ := os.Open("/tmp/large-file.json")
130-
iter := Parse(ConfigDefault, file, 4096)
131+
iter := jsoniter.Parse(jsoniter.ConfigDefault, file, 4096)
131132
count := 0
132-
iter.ReadArrayCB(func(iter *Iterator) bool {
133+
iter.ReadArrayCB(func(iter *jsoniter.Iterator) bool {
133134
// Skip() is strict by default, use --tags jsoniter-sloppy to skip without validation
134135
iter.Skip()
135136
count++

jsoniter_io_test.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

jsoniter_map_test.go

Lines changed: 0 additions & 160 deletions
This file was deleted.
Lines changed: 5 additions & 4 deletions
Large diffs are not rendered by default.

misc_tests/jsoniter_map_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package misc_tests
2+
3+
import (
4+
"encoding/json"
5+
"math/big"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
"strings"
10+
"github.com/json-iterator/go"
11+
)
12+
13+
func Test_decode_TextMarshaler_key_map(t *testing.T) {
14+
should := require.New(t)
15+
var val map[*big.Float]string
16+
should.Nil(jsoniter.UnmarshalFromString(`{"1":"2"}`, &val))
17+
str, err := jsoniter.MarshalToString(val)
18+
should.Nil(err)
19+
should.Equal(`{"1":"2"}`, str)
20+
}
21+
22+
func Test_read_map_with_reader(t *testing.T) {
23+
should := require.New(t)
24+
input := `{"branch":"beta","change_log":"add the rows{10}","channel":"fros","create_time":"2017-06-13 16:39:08","firmware_list":"","md5":"80dee2bf7305bcf179582088e29fd7b9","note":{"CoreServices":{"md5":"d26975c0a8c7369f70ed699f2855cc2e","package_name":"CoreServices","version_code":"76","version_name":"1.0.76"},"FrDaemon":{"md5":"6b1f0626673200bc2157422cd2103f5d","package_name":"FrDaemon","version_code":"390","version_name":"1.0.390"},"FrGallery":{"md5":"90d767f0f31bcd3c1d27281ec979ba65","package_name":"FrGallery","version_code":"349","version_name":"1.0.349"},"FrLocal":{"md5":"f15a215b2c070a80a01f07bde4f219eb","package_name":"FrLocal","version_code":"791","version_name":"1.0.791"}},"pack_region_urls":{"CN":"https://s3.cn-north-1.amazonaws.com.cn/xxx-os/ttt_xxx_android_1.5.3.344.393.zip","default":"http://192.168.8.78/ttt_xxx_android_1.5.3.344.393.zip","local":"http://192.168.8.78/ttt_xxx_android_1.5.3.344.393.zip"},"pack_version":"1.5.3.344.393","pack_version_code":393,"region":"all","release_flag":0,"revision":62,"size":38966875,"status":3}`
25+
reader := strings.NewReader(input)
26+
decoder := jsoniter.ConfigCompatibleWithStandardLibrary.NewDecoder(reader)
27+
m1 := map[string]interface{}{}
28+
should.Nil(decoder.Decode(&m1))
29+
m2 := map[string]interface{}{}
30+
should.Nil(json.Unmarshal([]byte(input), &m2))
31+
should.Equal(m2, m1)
32+
should.Equal("1.0.76", m1["note"].(map[string]interface{})["CoreServices"].(map[string]interface{})["version_name"])
33+
}

0 commit comments

Comments
 (0)