1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

support null/true/false

This commit is contained in:
Tao Wen
2016-12-02 11:22:20 +08:00
parent 05a9df4749
commit ce5b193569
6 changed files with 358 additions and 31 deletions

View File

@ -45,6 +45,16 @@ func Test_skip_array(t *testing.T) {
}
}
func Test_skip_empty_array(t *testing.T) {
iter := ParseString(`[ [ ], "b"]`)
iter.ReadArray()
iter.Skip()
iter.ReadArray()
if iter.ReadString() != "b" {
t.FailNow()
}
}
func Test_skip_object(t *testing.T) {
iter := ParseString(`[ {"a" : {"b": "c"}, "d": 102 }, "b"]`)
iter.ReadArray()
@ -55,6 +65,16 @@ func Test_skip_object(t *testing.T) {
}
}
func Test_skip_empty_object(t *testing.T) {
iter := ParseString(`[ { }, "b"]`)
iter.ReadArray()
iter.Skip()
iter.ReadArray()
if iter.ReadString() != "b" {
t.FailNow()
}
}
func Test_skip_nested(t *testing.T) {
iter := ParseString(`[ {"a" : [{"b": "c"}], "d": 102 }, "b"]`)
iter.ReadArray()
@ -70,16 +90,13 @@ type TestResp struct {
}
func Benchmark_jsoniter_skip(b *testing.B) {
for n := 0; n < b.N; n++ {
result := TestResp{}
iter := ParseString(`
input := []byte(`
{
"_shards":{
"total" : 5,
"successful" : 5,
"failed" : 0
},
"code": 200,
"hits":{
"total" : 1,
"hits" : [
@ -94,8 +111,12 @@ func Benchmark_jsoniter_skip(b *testing.B) {
}
}
]
}
},
"code": 200
}`)
for n := 0; n < b.N; n++ {
result := TestResp{}
iter := ParseBytes(input)
for field := iter.ReadObject(); field != ""; field = iter.ReadObject() {
switch field {
case "code":
@ -108,16 +129,13 @@ func Benchmark_jsoniter_skip(b *testing.B) {
}
func Benchmark_json_skip(b *testing.B) {
for n := 0; n < b.N; n++ {
result := TestResp{}
json.Unmarshal([]byte(`
input := []byte(`
{
"_shards":{
"total" : 5,
"successful" : 5,
"failed" : 0
},
"code": 200,
"hits":{
"total" : 1,
"hits" : [
@ -132,7 +150,11 @@ func Benchmark_json_skip(b *testing.B) {
}
}
]
}
}`), &result)
},
"code": 200
}`)
for n := 0; n < b.N; n++ {
result := TestResp{}
json.Unmarshal(input, &result)
}
}