Skip to content

Commit

Permalink
test: fuzz roundtrip
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Aug 29, 2022
1 parent e928cf0 commit a867144
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions fuzz/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ func fuzzMain(t *testing.T, data []byte) {
jout, jerr := json.Marshal(jv)
require.NoError(t, serr, "error in sonic marshal %v", reflect.TypeOf(jv))
require.NoError(t, jerr, "error in json marshal %v", reflect.TypeOf(jv))
// not comparing here because sonic marshal is different from encoding/json, as:
// case 1: 1.23e2 -> `1.23e2` in sonic, but 1.23e2 -> `1.23e+2` in encoding/json
// case 2: "\b" -> `\\b` in sonic, but `\u0008` in encoding/json
// require.Equal(t, sout, jout, "different in sonic marshal %v", reflect.TypeOf(jv))
var _, _ = sout, jout

{
sv, jv := typ(), typ()
serr := sonic.Unmarshal(sout, sv)
jerr := json.Unmarshal(jout, jv)
require.Equalf(t, serr != nil, jerr != nil, "different error in sonic unmarshal again %v", reflect.TypeOf(jv))
if jerr != nil {
return
}
require.Equal(t, sv, jv, "different result in sonic unmarshal again %v", reflect.TypeOf(jv))
}

if m, ok := sv.(*map[string]interface{}); ok {
fuzzDynamicStruct(t, jout, *m)
fuzzASTGetFromObject(t, jout, *m)
Expand Down

0 comments on commit a867144

Please sign in to comment.