diff options
-rw-r--r-- | compat/json/compat_test.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/compat/json/compat_test.go b/compat/json/compat_test.go index 52ed60e..df50266 100644 --- a/compat/json/compat_test.go +++ b/compat/json/compat_test.go @@ -11,7 +11,8 @@ import ( "testing" "github.com/stretchr/testify/assert" - + // When adding new testcases, comment this out and import + // "encoding/json", to validate your testcase. "git.lukeshu.com/go/lowmemjson/compat/json" ) @@ -155,6 +156,7 @@ func TestCompatMarshal(t *testing.T) { "urc": {In: "\ufffd", Out: "\"\ufffd\""}, "float": {In: 1.2e3, Out: `1200`}, "obj": {In: map[string]any{"": 1, " ": 2}, Out: `{"":1," ":2}`}, + "byte-ary": {In: struct{ Label [5]byte }{}, Out: `{"Label":[0,0,0,0,0]}`}, } for tcName, tc := range testcases { tc := tc @@ -189,6 +191,7 @@ func TestCompatUnmarshal(t *testing.T) { "two-numbers1": {In: `00`, ExpOut: nil, ExpErr: `invalid character '0' after top-level value`}, "two-numbers2": {In: `1 2`, ExpOut: nil, ExpErr: `invalid character '2' after top-level value`}, "invalid-utf8": {In: "\x85", ExpErr: `invalid character '\x85' looking for beginning of value`}, + "byte-ary": {In: `{"Label":[1,0,0,0,0]}`, InPtr: new(struct{ Label [5]byte }), ExpOut: struct{ Label [5]byte }{Label: [5]byte{1, 0, 0, 0, 0}}}, // 2e308 is slightly more than math.MaxFloat64 (~1.79e308) "obj-overflow": {In: `{"foo":"bar", "baz":2e308, "qux": "orb"}`, ExpOut: map[string]any{"foo": "bar", "baz": nil, "qux": "orb"}, ExpErr: `json: cannot unmarshal number 2e308 into Go value of type float64`}, "ary-overflow": {In: `["foo",2e308,"bar",3e308]`, ExpOut: []any{"foo", nil, "bar", nil}, ExpErr: `json: cannot unmarshal number 2e308 into Go value of type float64`}, |