1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-24 23:16:47 +02:00

#53 extract out config

This commit is contained in:
Tao Wen
2017-06-13 16:58:53 +08:00
parent 788918b85d
commit acddcf5bbf
33 changed files with 328 additions and 300 deletions

View File

@ -9,10 +9,10 @@ import (
func Test_empty_object(t *testing.T) {
should := require.New(t)
iter := ParseString(`{}`)
iter := ParseString(DEFAULT_CONFIG, `{}`)
field := iter.ReadObject()
should.Equal("", field)
iter = ParseString(`{}`)
iter = ParseString(DEFAULT_CONFIG, `{}`)
iter.ReadObjectCB(func(iter *Iterator, field string) bool {
should.FailNow("should not call")
return true
@ -21,14 +21,14 @@ func Test_empty_object(t *testing.T) {
func Test_one_field(t *testing.T) {
should := require.New(t)
iter := ParseString(`{"a": "b"}`)
iter := ParseString(DEFAULT_CONFIG, `{"a": "b"}`)
field := iter.ReadObject()
should.Equal("a", field)
value := iter.ReadString()
should.Equal("b", value)
field = iter.ReadObject()
should.Equal("", field)
iter = ParseString(`{"a": "b"}`)
iter = ParseString(DEFAULT_CONFIG, `{"a": "b"}`)
should.True(iter.ReadObjectCB(func(iter *Iterator, field string) bool {
should.Equal("a", field)
return true
@ -37,7 +37,7 @@ func Test_one_field(t *testing.T) {
func Test_two_field(t *testing.T) {
should := require.New(t)
iter := ParseString(`{ "a": "b" , "c": "d" }`)
iter := ParseString(DEFAULT_CONFIG, `{ "a": "b" , "c": "d" }`)
field := iter.ReadObject()
should.Equal("a", field)
value := iter.ReadString()
@ -48,7 +48,7 @@ func Test_two_field(t *testing.T) {
should.Equal("d", value)
field = iter.ReadObject()
should.Equal("", field)
iter = ParseString(`{"field1": "1", "field2": 2}`)
iter = ParseString(DEFAULT_CONFIG, `{"field1": "1", "field2": 2}`)
for field := iter.ReadObject(); field != ""; field = iter.ReadObject() {
switch field {
case "field1":
@ -210,7 +210,7 @@ func Test_object_wrapper_any_get_all(t *testing.T) {
func Test_write_object(t *testing.T) {
should := require.New(t)
buf := &bytes.Buffer{}
stream := NewStream(buf, 4096)
stream := NewStream(DEFAULT_CONFIG, buf, 4096)
stream.IndentionStep = 2
stream.WriteObjectStart()
stream.WriteObjectField("hello")
@ -230,7 +230,7 @@ func Benchmark_jsoniter_object(b *testing.B) {
Field2 uint64
}
for n := 0; n < b.N; n++ {
iter := ParseString(`{"field1": "1", "field2": 2}`)
iter := ParseString(DEFAULT_CONFIG, `{"field1": "1", "field2": 2}`)
obj := TestObj{}
for field := iter.ReadObject(); field != ""; field = iter.ReadObject() {
switch field {