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

Revert "Merge pull request #418 from bbrks/configurable_maxDepth"

This reverts commit 44a7e7340d, reversing
changes made to dc11f49689.
This commit is contained in:
Jordan Liggitt
2019-12-19 19:06:29 -05:00
parent 44a7e7340d
commit 7c9f8c2d20
3 changed files with 5 additions and 52 deletions

View File

@ -2,11 +2,9 @@ package test
import (
"encoding/json"
"fmt"
"strings"
"testing"
jsoniter "github.com/json-iterator/go"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
)
@ -26,44 +24,6 @@ func Test_customize_float_marshal(t *testing.T) {
should.Equal("1.234568", str)
}
func Test_max_depth(t *testing.T) {
deepJSON := func(depth int) []byte {
return []byte(strings.Repeat(`[`, depth) + strings.Repeat(`]`, depth))
}
tests := []struct {
jsonDepth int
cfgMaxDepth int
expectedErr string
}{
// Test the default depth
{jsonDepth: 10000, cfgMaxDepth: 0},
{jsonDepth: 10001, cfgMaxDepth: 0, expectedErr: "max depth"},
// Test max depth logic
{jsonDepth: 5, cfgMaxDepth: 6},
{jsonDepth: 5, cfgMaxDepth: 5},
{jsonDepth: 5, cfgMaxDepth: 4, expectedErr: "max depth"},
// Try a large depth without a limit
{jsonDepth: 128000, cfgMaxDepth: -1},
}
for _, test := range tests {
t.Run(fmt.Sprintf("jsonDepth:%v_cfgMaxDepth:%v", test.jsonDepth, test.cfgMaxDepth), func(t *testing.T) {
should := require.New(t)
cfg := jsoniter.Config{MaxDepth: test.cfgMaxDepth}.Froze()
var val interface{}
err := cfg.Unmarshal(deepJSON(test.jsonDepth), &val)
if test.expectedErr != "" {
should.Error(err)
should.Contains(err.Error(), test.expectedErr)
} else {
should.NoError(err)
}
})
}
}
func Test_customize_tag_key(t *testing.T) {
type TestObject struct {