Merge pull request #3651 from nspcc-dev/tojson-test

stackitem: extend ToJSON test
This commit is contained in:
Anna Shaleva 2024-10-30 20:01:45 +03:00 committed by GitHub
commit e8b8c1a4b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -203,6 +203,18 @@ func TestToJSONCornerCases(t *testing.T) {
m.Add(Make([]byte{0xe9}), Make(true)) m.Add(Make([]byte{0xe9}), Make(true))
testToJSON(t, ErrInvalidValue, m) testToJSON(t, ErrInvalidValue, m)
}) })
t.Run("circular reference", func(t *testing.T) {
m := NewMap()
m.Add(Make("one"), Make(true))
// No circular reference, ensure it can be properly serialized.
arr := NewArray([]Item{m, m})
testToJSON(t, nil, arr)
// With circular reference, error expected.
m.Add(Make("two"), arr)
testToJSON(t, ErrTooBig, arr)
})
} }
// getBigArray returns array takes up a lot of storage when serialized. // getBigArray returns array takes up a lot of storage when serialized.