diff --git a/output_tests/struct/alias/json_test.go b/output_tests/struct/alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/alias/types.go b/output_tests/struct/alias/types.go deleted file mode 100644 index 947ada6..0000000 --- a/output_tests/struct/alias/types.go +++ /dev/null @@ -1,20 +0,0 @@ -package test - -type typeA struct { - Byte1 byte - Byte2 byte - Bool1 bool - Bool2 bool - Int8 int8 - Int16 int16 - Int32 int32 - Uint8 uint8 - Uint16 uint16 - Uint32 uint32 - Float32 float32 - Float64 float64 - String1 string - String2 string -} - -type typeForTest typeA diff --git a/output_tests/struct/anonymous/no_overlap/float64/json_test.go b/output_tests/struct/anonymous/no_overlap/float64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/float64/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/float64/types.go b/output_tests/struct/anonymous/no_overlap/float64/types.go deleted file mode 100644 index 1f45482..0000000 --- a/output_tests/struct/anonymous/no_overlap/float64/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded float64 - -type typeForTest struct { - Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/int32/json_test.go b/output_tests/struct/anonymous/no_overlap/int32/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/int32/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/int32/types.go b/output_tests/struct/anonymous/no_overlap/int32/types.go deleted file mode 100644 index a7275ed..0000000 --- a/output_tests/struct/anonymous/no_overlap/int32/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded int32 - -type typeForTest struct { - Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/json_marshal/json_test.go b/output_tests/struct/anonymous/no_overlap/json_marshal/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/json_marshal/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/json_marshal/types.go b/output_tests/struct/anonymous/no_overlap/json_marshal/types.go deleted file mode 100644 index 36c5e57..0000000 --- a/output_tests/struct/anonymous/no_overlap/json_marshal/types.go +++ /dev/null @@ -1,57 +0,0 @@ -package test - -import ( - "bytes" - "encoding/base64" - "encoding/json" - "strings" -) - -// MarshalerForTest TEST ONLY -type MarshalerForTest string - -func encode(str string) string { - buf := bytes.Buffer{} - b64 := base64.NewEncoder(base64.StdEncoding, &buf) - if _, err := b64.Write([]byte(str)); err != nil { - panic(err) - } - if err := b64.Close(); err != nil { - panic(err) - } - return buf.String() -} - -func decode(str string) string { - if len(str) == 0 { - return "" - } - b64 := base64.NewDecoder(base64.StdEncoding, strings.NewReader(str)) - bs := make([]byte, len(str)) - if n, err := b64.Read(bs); err != nil { - panic(err) - } else { - bs = bs[:n] - } - return string(bs) -} - -// MarshalJSON TEST ONLY -func (m MarshalerForTest) MarshalJSON() ([]byte, error) { - return []byte(`"MANUAL__` + encode(string(m)) + `"`), nil -} - -// UnmarshalJSON TEST ONLY -func (m *MarshalerForTest) UnmarshalJSON(text []byte) error { - *m = MarshalerForTest(decode(strings.TrimPrefix(strings.Trim(string(text), `"`), "MANUAL__"))) - return nil -} - -var _ json.Marshaler = *new(MarshalerForTest) -var _ json.Unmarshaler = new(MarshalerForTest) - -type typeForTest struct { - F1 float64 - MarshalerForTest - F2 int32 -} diff --git a/output_tests/struct/anonymous/no_overlap/map_string_string/json_test.go b/output_tests/struct/anonymous/no_overlap/map_string_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/map_string_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/map_string_string/types.go b/output_tests/struct/anonymous/no_overlap/map_string_string/types.go deleted file mode 100644 index d56ee0a..0000000 --- a/output_tests/struct/anonymous/no_overlap/map_string_string/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded map[string]string - -type typeForTest struct { - Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_float64/json_test.go b/output_tests/struct/anonymous/no_overlap/ptr_float64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_float64/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_float64/types.go b/output_tests/struct/anonymous/no_overlap/ptr_float64/types.go deleted file mode 100644 index dbf0492..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_float64/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded float64 - -type typeForTest struct { - *Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_int32/json_test.go b/output_tests/struct/anonymous/no_overlap/ptr_int32/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_int32/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_int32/types.go b/output_tests/struct/anonymous/no_overlap/ptr_int32/types.go deleted file mode 100644 index 24294e2..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_int32/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded int32 - -type typeForTest struct { - *Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_map_string_string/json_test.go b/output_tests/struct/anonymous/no_overlap/ptr_map_string_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_map_string_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_map_string_string/types.go b/output_tests/struct/anonymous/no_overlap/ptr_map_string_string/types.go deleted file mode 100644 index 40dbec6..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_map_string_string/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded map[string]string - -type typeForTest struct { - *Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_slice_string/json_test.go b/output_tests/struct/anonymous/no_overlap/ptr_slice_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_slice_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_slice_string/types.go b/output_tests/struct/anonymous/no_overlap/ptr_slice_string/types.go deleted file mode 100644 index 297b6af..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_slice_string/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded []string - -type typeForTest struct { - *Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_string/json_test.go b/output_tests/struct/anonymous/no_overlap/ptr_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_string/types.go b/output_tests/struct/anonymous/no_overlap/ptr_string/types.go deleted file mode 100644 index 06f4138..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_string/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded string - -type typeForTest struct { - *Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_struct_various/json_test.go b/output_tests/struct/anonymous/no_overlap/ptr_struct_various/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_struct_various/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/ptr_struct_various/types.go b/output_tests/struct/anonymous/no_overlap/ptr_struct_various/types.go deleted file mode 100644 index 6a30819..0000000 --- a/output_tests/struct/anonymous/no_overlap/ptr_struct_various/types.go +++ /dev/null @@ -1,17 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded struct { - String string - Int int32 - Float float64 - Struct struct { - X string - } - Slice []string - Map map[string]string -} - -type typeForTest struct { - *Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/slice_string/json_test.go b/output_tests/struct/anonymous/no_overlap/slice_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/slice_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/slice_string/types.go b/output_tests/struct/anonymous/no_overlap/slice_string/types.go deleted file mode 100644 index 9c20be3..0000000 --- a/output_tests/struct/anonymous/no_overlap/slice_string/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded []string - -type typeForTest struct { - Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/string/json_test.go b/output_tests/struct/anonymous/no_overlap/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/string/types.go b/output_tests/struct/anonymous/no_overlap/string/types.go deleted file mode 100644 index 7b153fa..0000000 --- a/output_tests/struct/anonymous/no_overlap/string/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded string - -type typeForTest struct { - Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/string_with_tag/json_test.go b/output_tests/struct/anonymous/no_overlap/string_with_tag/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/string_with_tag/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/string_with_tag/types.go b/output_tests/struct/anonymous/no_overlap/string_with_tag/types.go deleted file mode 100644 index 3e0919a..0000000 --- a/output_tests/struct/anonymous/no_overlap/string_with_tag/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded string - -type typeForTest struct { - Embedded `json:"othername"` -} diff --git a/output_tests/struct/anonymous/no_overlap/struct_various/json_test.go b/output_tests/struct/anonymous/no_overlap/struct_various/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/struct_various/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/no_overlap/struct_various/types.go b/output_tests/struct/anonymous/no_overlap/struct_various/types.go deleted file mode 100644 index d7eaeaa..0000000 --- a/output_tests/struct/anonymous/no_overlap/struct_various/types.go +++ /dev/null @@ -1,17 +0,0 @@ -package test - -// Embedded TEST ONLY -type Embedded struct { - String string - Int int32 - Float float64 - Struct struct { - X string - } - Slice []string - Map map[string]string -} - -type typeForTest struct { - Embedded -} diff --git a/output_tests/struct/anonymous/no_overlap/text_marshal/json_test.go b/output_tests/struct/anonymous/no_overlap/text_marshal/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/no_overlap/text_marshal/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/different_levels/json_test.go b/output_tests/struct/anonymous/overlap/different_levels/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/overlap/different_levels/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/different_levels/types.go b/output_tests/struct/anonymous/overlap/different_levels/types.go deleted file mode 100644 index 4c169ae..0000000 --- a/output_tests/struct/anonymous/overlap/different_levels/types.go +++ /dev/null @@ -1,17 +0,0 @@ -package test - -// E1 TEST ONLY -type E1 struct { - F1 int32 -} - -// E2 TEST ONLY -type E2 struct { - F2 string -} - -type typeForTest struct { - E1 - E2 - F1 string -} diff --git a/output_tests/struct/anonymous/overlap/ignore_deeper_level/json_test.go b/output_tests/struct/anonymous/overlap/ignore_deeper_level/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/overlap/ignore_deeper_level/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/ignore_deeper_level/types.go b/output_tests/struct/anonymous/overlap/ignore_deeper_level/types.go deleted file mode 100644 index 3da8950..0000000 --- a/output_tests/struct/anonymous/overlap/ignore_deeper_level/types.go +++ /dev/null @@ -1,23 +0,0 @@ -package test - -// DoubleEmbedded TEST ONLY -type DoubleEmbedded struct { - F1 int32 `json:"F1"` -} - -// Embedded1 TEST ONLY -type Embedded1 struct { - DoubleEmbedded - F1 int32 -} - -// Embedded2 TEST ONLY -type Embedded2 struct { - F1 int32 `json:"F1"` - DoubleEmbedded -} - -type typeForTest struct { - Embedded1 - Embedded2 -} diff --git a/output_tests/struct/anonymous/overlap/same_level_1_both_tagged/json_test.go b/output_tests/struct/anonymous/overlap/same_level_1_both_tagged/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_1_both_tagged/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/same_level_1_both_tagged/types.go b/output_tests/struct/anonymous/overlap/same_level_1_both_tagged/types.go deleted file mode 100644 index 4ef30d6..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_1_both_tagged/types.go +++ /dev/null @@ -1,16 +0,0 @@ -package test - -// Embedded1 TEST ONLY -type Embedded1 struct { - F1 int32 `json:"F1"` -} - -// Embedded2 TEST ONLY -type Embedded2 struct { - F1 int32 `json:"F1"` -} - -type typeForTest struct { - Embedded1 - Embedded2 -} diff --git a/output_tests/struct/anonymous/overlap/same_level_1_no_tags/json_test.go b/output_tests/struct/anonymous/overlap/same_level_1_no_tags/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_1_no_tags/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/same_level_1_no_tags/types.go b/output_tests/struct/anonymous/overlap/same_level_1_no_tags/types.go deleted file mode 100644 index 88f3596..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_1_no_tags/types.go +++ /dev/null @@ -1,16 +0,0 @@ -package test - -// Embedded1 TEST ONLY -type Embedded1 struct { - F1 int32 -} - -// Embedded2 TEST ONLY -type Embedded2 struct { - F1 int32 -} - -type typeForTest struct { - Embedded1 - Embedded2 -} diff --git a/output_tests/struct/anonymous/overlap/same_level_1_tagged/json_test.go b/output_tests/struct/anonymous/overlap/same_level_1_tagged/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_1_tagged/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/same_level_1_tagged/types.go b/output_tests/struct/anonymous/overlap/same_level_1_tagged/types.go deleted file mode 100644 index 180b9b7..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_1_tagged/types.go +++ /dev/null @@ -1,16 +0,0 @@ -package test - -// Embedded1 TEST ONLY -type Embedded1 struct { - F1 int32 -} - -// Embedded2 TEST ONLY -type Embedded2 struct { - F1 int32 `json:"F1"` -} - -type typeForTest struct { - Embedded1 - Embedded2 -} diff --git a/output_tests/struct/anonymous/overlap/same_level_2_both_tagged/json_test.go b/output_tests/struct/anonymous/overlap/same_level_2_both_tagged/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_2_both_tagged/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/same_level_2_both_tagged/types.go b/output_tests/struct/anonymous/overlap/same_level_2_both_tagged/types.go deleted file mode 100644 index 3265085..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_2_both_tagged/types.go +++ /dev/null @@ -1,26 +0,0 @@ -package test - -// DoubleEmbedded1 TEST ONLY -type DoubleEmbedded1 struct { - F1 int32 `json:"F1"` -} - -// Embedded1 TEST ONLY -type Embedded1 struct { - DoubleEmbedded1 -} - -// DoubleEmbedded2 TEST ONLY -type DoubleEmbedded2 struct { - F1 int32 `json:"F1"` -} - -// Embedded2 TEST ONLY -type Embedded2 struct { - DoubleEmbedded2 -} - -type typeForTest struct { - Embedded1 - Embedded2 -} diff --git a/output_tests/struct/anonymous/overlap/same_level_2_no_tags/json_test.go b/output_tests/struct/anonymous/overlap/same_level_2_no_tags/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_2_no_tags/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/same_level_2_no_tags/types.go b/output_tests/struct/anonymous/overlap/same_level_2_no_tags/types.go deleted file mode 100644 index 5b20d89..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_2_no_tags/types.go +++ /dev/null @@ -1,26 +0,0 @@ -package test - -// DoubleEmbedded1 TEST ONLY -type DoubleEmbedded1 struct { - F1 int32 -} - -// Embedded1 TEST ONLY -type Embedded1 struct { - DoubleEmbedded1 -} - -// DoubleEmbedded2 TEST ONLY -type DoubleEmbedded2 struct { - F1 int32 -} - -// Embedded2 TEST ONLY -type Embedded2 struct { - DoubleEmbedded2 -} - -type typeForTest struct { - Embedded1 - Embedded2 -} diff --git a/output_tests/struct/anonymous/overlap/same_level_2_tagged/json_test.go b/output_tests/struct/anonymous/overlap/same_level_2_tagged/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_2_tagged/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/anonymous/overlap/same_level_2_tagged/types.go b/output_tests/struct/anonymous/overlap/same_level_2_tagged/types.go deleted file mode 100644 index 97f9e23..0000000 --- a/output_tests/struct/anonymous/overlap/same_level_2_tagged/types.go +++ /dev/null @@ -1,26 +0,0 @@ -package test - -// DoubleEmbedded1 TEST ONLY -type DoubleEmbedded1 struct { - F1 int32 -} - -// Embedded1 TEST ONLY -type Embedded1 struct { - DoubleEmbedded1 -} - -// DoubleEmbedded2 TEST ONLY -type DoubleEmbedded2 struct { - F1 int32 `json:"F1"` -} - -// Embedded2 TEST ONLY -type Embedded2 struct { - DoubleEmbedded2 -} - -type typeForTest struct { - Embedded1 - Embedded2 -} diff --git a/output_tests/struct/array/ptr_string/json_test.go b/output_tests/struct/array/ptr_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/array/ptr_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/array/ptr_string/types.go b/output_tests/struct/array/ptr_string/types.go deleted file mode 100644 index 77b3235..0000000 --- a/output_tests/struct/array/ptr_string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F [4]*string -} diff --git a/output_tests/struct/array/string/json_test.go b/output_tests/struct/array/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/array/string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/array/string/types.go b/output_tests/struct/array/string/types.go deleted file mode 100644 index 6652ad8..0000000 --- a/output_tests/struct/array/string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F [4]string -} diff --git a/output_tests/struct/array/string_alias/json_test.go b/output_tests/struct/array/string_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/array/string_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/array/string_alias/types.go b/output_tests/struct/array/string_alias/types.go deleted file mode 100644 index 1d4ce49..0000000 --- a/output_tests/struct/array/string_alias/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeA1 string -type typeA2 [4]typeA1 - -type typeForTest struct { - F1 [4]typeA1 - F2 typeA2 -} diff --git a/output_tests/struct/array/strings/json_test.go b/output_tests/struct/array/strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/array/strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/array/strings/types.go b/output_tests/struct/array/strings/types.go deleted file mode 100644 index 9217b5d..0000000 --- a/output_tests/struct/array/strings/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 [4]string - F2 [4]string - F3 [4]string -} diff --git a/output_tests/struct/array/struct_strings/json_test.go b/output_tests/struct/array/struct_strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/array/struct_strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/array/struct_strings/types.go b/output_tests/struct/array/struct_strings/types.go deleted file mode 100644 index 87fc996..0000000 --- a/output_tests/struct/array/struct_strings/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F [4]struct { - F1 string - F2 string - F3 string - } -} diff --git a/output_tests/struct/empty/json_test.go b/output_tests/struct/empty/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/empty/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/empty/types.go b/output_tests/struct/empty/types.go deleted file mode 100644 index b6b45df..0000000 --- a/output_tests/struct/empty/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest struct{} diff --git a/output_tests/struct/empty_alias/json_test.go b/output_tests/struct/empty_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/empty_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/empty_alias/types.go b/output_tests/struct/empty_alias/types.go deleted file mode 100644 index c50475a..0000000 --- a/output_tests/struct/empty_alias/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeA struct{} - -type typeForTest typeA diff --git a/output_tests/struct/everything/json_test.go b/output_tests/struct/everything/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/everything/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/everything/types.go b/output_tests/struct/everything/types.go deleted file mode 100644 index c287fa4..0000000 --- a/output_tests/struct/everything/types.go +++ /dev/null @@ -1,20 +0,0 @@ -package test - -type typeForTest struct { - Byte1 byte - Byte2 byte - Bool1 bool - Bool2 bool - Int8 int8 - Int16 int16 - Int32 int32 - Int64 int64 - Uint8 uint8 - Uint16 uint16 - Uint32 uint32 - Uint64 uint64 - Float32 float32 - Float64 float64 - String1 string - String2 string -} diff --git a/output_tests/struct/float64/json_test.go b/output_tests/struct/float64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/float64/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/float64/types.go b/output_tests/struct/float64/types.go deleted file mode 100644 index c8873ea..0000000 --- a/output_tests/struct/float64/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F float64 -} diff --git a/output_tests/struct/float64_alias/json_test.go b/output_tests/struct/float64_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/float64_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/float64_alias/types.go b/output_tests/struct/float64_alias/types.go deleted file mode 100644 index 88a8ad1..0000000 --- a/output_tests/struct/float64_alias/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeA float64 - -type typeForTest struct { - F typeA -} diff --git a/output_tests/struct/float64s/json_test.go b/output_tests/struct/float64s/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/float64s/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/float64s/types.go b/output_tests/struct/float64s/types.go deleted file mode 100644 index d9d5682..0000000 --- a/output_tests/struct/float64s/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 float64 - F2 float64 - F3 float64 -} diff --git a/output_tests/struct/float64s_alias/json_test.go b/output_tests/struct/float64s_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/float64s_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/float64s_alias/types.go b/output_tests/struct/float64s_alias/types.go deleted file mode 100644 index dfb4b56..0000000 --- a/output_tests/struct/float64s_alias/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeA float64 - -type typeForTest struct { - F1 typeA - F2 typeA - F3 typeA -} diff --git a/output_tests/struct/int32/json_test.go b/output_tests/struct/int32/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/int32/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/int32/types.go b/output_tests/struct/int32/types.go deleted file mode 100644 index ea5481b..0000000 --- a/output_tests/struct/int32/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F int32 -} diff --git a/output_tests/struct/int32_alias/json_test.go b/output_tests/struct/int32_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/int32_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/int32_alias/types.go b/output_tests/struct/int32_alias/types.go deleted file mode 100644 index fcafa26..0000000 --- a/output_tests/struct/int32_alias/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeA int32 - -type typeForTest struct { - F typeA -} diff --git a/output_tests/struct/int32s/json_test.go b/output_tests/struct/int32s/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/int32s/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/int32s/types.go b/output_tests/struct/int32s/types.go deleted file mode 100644 index f7c078b..0000000 --- a/output_tests/struct/int32s/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 int32 - F2 int32 - F3 int32 -} diff --git a/output_tests/struct/int32s_alias/json_test.go b/output_tests/struct/int32s_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/int32s_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/int32s_alias/types.go b/output_tests/struct/int32s_alias/types.go deleted file mode 100644 index d168647..0000000 --- a/output_tests/struct/int32s_alias/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeA int32 - -type typeForTest struct { - F1 typeA - F2 typeA - F3 typeA -} diff --git a/output_tests/struct/int64/json_test.go b/output_tests/struct/int64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/int64/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/int64/types.go b/output_tests/struct/int64/types.go deleted file mode 100644 index cf77016..0000000 --- a/output_tests/struct/int64/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F int64 -} diff --git a/output_tests/struct/map/int32_ptr_string/json_test.go b/output_tests/struct/map/int32_ptr_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/map/int32_ptr_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/map/int32_ptr_string/types.go b/output_tests/struct/map/int32_ptr_string/types.go deleted file mode 100644 index 17d7a1f..0000000 --- a/output_tests/struct/map/int32_ptr_string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F map[int32]*string -} diff --git a/output_tests/struct/map/int32_string/json_test.go b/output_tests/struct/map/int32_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/map/int32_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/map/int32_string/types.go b/output_tests/struct/map/int32_string/types.go deleted file mode 100644 index f800fc1..0000000 --- a/output_tests/struct/map/int32_string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F map[int32]string -} diff --git a/output_tests/struct/map/int32_struct_strings/json_test.go b/output_tests/struct/map/int32_struct_strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/map/int32_struct_strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/map/int32_struct_strings/types.go b/output_tests/struct/map/int32_struct_strings/types.go deleted file mode 100644 index 03c7ba3..0000000 --- a/output_tests/struct/map/int32_struct_strings/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F map[int32]struct { - F1 string - F2 string - F3 string - } -} diff --git a/output_tests/struct/map/string_ptr_string/json_test.go b/output_tests/struct/map/string_ptr_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/map/string_ptr_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/map/string_ptr_string/types.go b/output_tests/struct/map/string_ptr_string/types.go deleted file mode 100644 index 239b86d..0000000 --- a/output_tests/struct/map/string_ptr_string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F map[string]*string -} diff --git a/output_tests/struct/map/string_string/json_test.go b/output_tests/struct/map/string_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/map/string_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/map/string_string/types.go b/output_tests/struct/map/string_string/types.go deleted file mode 100644 index 4f40367..0000000 --- a/output_tests/struct/map/string_string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F map[string]string -} diff --git a/output_tests/struct/map/string_struct_strings/json_test.go b/output_tests/struct/map/string_struct_strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/map/string_struct_strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/map/string_struct_strings/types.go b/output_tests/struct/map/string_struct_strings/types.go deleted file mode 100644 index a65d76d..0000000 --- a/output_tests/struct/map/string_struct_strings/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F map[string]struct { - F1 string - F2 string - F3 string - } -} diff --git a/output_tests/struct/ptr_float64/json_test.go b/output_tests/struct/ptr_float64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_float64/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_float64/types.go b/output_tests/struct/ptr_float64/types.go deleted file mode 100644 index f9fe8f8..0000000 --- a/output_tests/struct/ptr_float64/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F *float64 -} diff --git a/output_tests/struct/ptr_float64_alias/json_test.go b/output_tests/struct/ptr_float64_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_float64_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_float64_alias/types.go b/output_tests/struct/ptr_float64_alias/types.go deleted file mode 100644 index fdcc1df..0000000 --- a/output_tests/struct/ptr_float64_alias/types.go +++ /dev/null @@ -1,10 +0,0 @@ -package test - -type typeA1 float64 -type typeA2 *float64 - -type typeForTest struct { - F1 *typeA1 - F2 typeA2 - F3 *typeA2 -} diff --git a/output_tests/struct/ptr_int32/json_test.go b/output_tests/struct/ptr_int32/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_int32/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_int32/types.go b/output_tests/struct/ptr_int32/types.go deleted file mode 100644 index 2e0a1d8..0000000 --- a/output_tests/struct/ptr_int32/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F *int32 -} diff --git a/output_tests/struct/ptr_int32_alias/json_test.go b/output_tests/struct/ptr_int32_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_int32_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_int32_alias/types.go b/output_tests/struct/ptr_int32_alias/types.go deleted file mode 100644 index 96b1fff..0000000 --- a/output_tests/struct/ptr_int32_alias/types.go +++ /dev/null @@ -1,11 +0,0 @@ -package test - -type typeA1 int32 - -type typeA2 *int32 - -type typeForTest struct { - F1 *typeA1 - F2 typeA2 - F3 *typeA2 -} diff --git a/output_tests/struct/ptr_ptr_struct_empty/json_test.go b/output_tests/struct/ptr_ptr_struct_empty/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_ptr_struct_empty/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_ptr_struct_empty/types.go b/output_tests/struct/ptr_ptr_struct_empty/types.go deleted file mode 100644 index 365ad55..0000000 --- a/output_tests/struct/ptr_ptr_struct_empty/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F **struct{} -} diff --git a/output_tests/struct/ptr_ptr_struct_strings/json_test.go b/output_tests/struct/ptr_ptr_struct_strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_ptr_struct_strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_ptr_struct_strings/types.go b/output_tests/struct/ptr_ptr_struct_strings/types.go deleted file mode 100644 index a56eb20..0000000 --- a/output_tests/struct/ptr_ptr_struct_strings/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F **struct { - F1 string - F2 string - F3 string - } -} diff --git a/output_tests/struct/ptr_string/json_test.go b/output_tests/struct/ptr_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_string/types.go b/output_tests/struct/ptr_string/types.go deleted file mode 100644 index 3b7d5b3..0000000 --- a/output_tests/struct/ptr_string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F *string -} diff --git a/output_tests/struct/ptr_string_alias/json_test.go b/output_tests/struct/ptr_string_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_string_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_string_alias/types.go b/output_tests/struct/ptr_string_alias/types.go deleted file mode 100644 index cc19b97..0000000 --- a/output_tests/struct/ptr_string_alias/types.go +++ /dev/null @@ -1,10 +0,0 @@ -package test - -type typeA1 string -type typeA2 *string - -type typeForTest struct { - F1 *typeA1 - F2 typeA2 - F3 *typeA2 -} diff --git a/output_tests/struct/ptr_struct_empty/json_test.go b/output_tests/struct/ptr_struct_empty/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_struct_empty/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_struct_empty/types.go b/output_tests/struct/ptr_struct_empty/types.go deleted file mode 100644 index 5783782..0000000 --- a/output_tests/struct/ptr_struct_empty/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F *struct{} -} diff --git a/output_tests/struct/ptr_struct_strings/json_test.go b/output_tests/struct/ptr_struct_strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptr_struct_strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptr_struct_strings/types.go b/output_tests/struct/ptr_struct_strings/types.go deleted file mode 100644 index 6f31051..0000000 --- a/output_tests/struct/ptr_struct_strings/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F *struct { - F1 string - F2 string - F3 string - } -} diff --git a/output_tests/struct/ptrs_float64/json_test.go b/output_tests/struct/ptrs_float64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptrs_float64/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptrs_float64/types.go b/output_tests/struct/ptrs_float64/types.go deleted file mode 100644 index 3972cfa..0000000 --- a/output_tests/struct/ptrs_float64/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 *float64 - F2 *float64 - F3 *float64 -} diff --git a/output_tests/struct/ptrs_int32/json_test.go b/output_tests/struct/ptrs_int32/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptrs_int32/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptrs_int32/types.go b/output_tests/struct/ptrs_int32/types.go deleted file mode 100644 index 46e04db..0000000 --- a/output_tests/struct/ptrs_int32/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 *int32 - F2 *int32 - F3 *int32 -} diff --git a/output_tests/struct/ptrs_string/json_test.go b/output_tests/struct/ptrs_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/ptrs_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/ptrs_string/types.go b/output_tests/struct/ptrs_string/types.go deleted file mode 100644 index 0030442..0000000 --- a/output_tests/struct/ptrs_string/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 *string - F2 *string - F3 *string -} diff --git a/output_tests/struct/slice/ptr_string/json_test.go b/output_tests/struct/slice/ptr_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/slice/ptr_string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/slice/ptr_string/types.go b/output_tests/struct/slice/ptr_string/types.go deleted file mode 100644 index dd83958..0000000 --- a/output_tests/struct/slice/ptr_string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F []*string -} diff --git a/output_tests/struct/slice/string/json_test.go b/output_tests/struct/slice/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/slice/string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/slice/string/types.go b/output_tests/struct/slice/string/types.go deleted file mode 100644 index ef61564..0000000 --- a/output_tests/struct/slice/string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F []string -} diff --git a/output_tests/struct/slice/string_alias/json_test.go b/output_tests/struct/slice/string_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/slice/string_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/slice/string_alias/types.go b/output_tests/struct/slice/string_alias/types.go deleted file mode 100644 index 3a95f53..0000000 --- a/output_tests/struct/slice/string_alias/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeA1 string -type typeA2 []typeA1 - -type typeForTest struct { - F1 []typeA1 - F2 typeA2 -} diff --git a/output_tests/struct/slice/strings/json_test.go b/output_tests/struct/slice/strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/slice/strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/slice/strings/types.go b/output_tests/struct/slice/strings/types.go deleted file mode 100644 index 7565c13..0000000 --- a/output_tests/struct/slice/strings/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 []string - F2 []string - F3 []string -} diff --git a/output_tests/struct/slice/struct_strings/json_test.go b/output_tests/struct/slice/struct_strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/slice/struct_strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/slice/struct_strings/types.go b/output_tests/struct/slice/struct_strings/types.go deleted file mode 100644 index 25fd464..0000000 --- a/output_tests/struct/slice/struct_strings/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F []struct { - F1 string - F2 string - F3 string - } -} diff --git a/output_tests/struct/string/json_test.go b/output_tests/struct/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/string/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/string/types.go b/output_tests/struct/string/types.go deleted file mode 100644 index a435657..0000000 --- a/output_tests/struct/string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F string -} diff --git a/output_tests/struct/string_alias/json_test.go b/output_tests/struct/string_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/string_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/string_alias/types.go b/output_tests/struct/string_alias/types.go deleted file mode 100644 index e4e785a..0000000 --- a/output_tests/struct/string_alias/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeA string - -type typeForTest struct { - F typeA -} diff --git a/output_tests/struct/strings/json_test.go b/output_tests/struct/strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/strings/types.go b/output_tests/struct/strings/types.go deleted file mode 100644 index fd978ca..0000000 --- a/output_tests/struct/strings/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 string - F2 string - F3 string -} diff --git a/output_tests/struct/strings_alias/json_test.go b/output_tests/struct/strings_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/strings_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/strings_alias/types.go b/output_tests/struct/strings_alias/types.go deleted file mode 100644 index e339766..0000000 --- a/output_tests/struct/strings_alias/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeA string - -type typeForTest struct { - F1 typeA - F2 typeA - F3 typeA -} diff --git a/output_tests/struct/struct/empties/json_test.go b/output_tests/struct/struct/empties/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/empties/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/empties/types.go b/output_tests/struct/struct/empties/types.go deleted file mode 100644 index 7eeb53d..0000000 --- a/output_tests/struct/struct/empties/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F1 struct{} - F2 struct{} - F3 struct{} -} diff --git a/output_tests/struct/struct/empty/json_test.go b/output_tests/struct/struct/empty/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/empty/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/empty/types.go b/output_tests/struct/struct/empty/types.go deleted file mode 100644 index 319f1e4..0000000 --- a/output_tests/struct/struct/empty/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest struct { - F struct{} -} diff --git a/output_tests/struct/struct/empty_alias/json_test.go b/output_tests/struct/struct/empty_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/empty_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/empty_alias/types.go b/output_tests/struct/struct/empty_alias/types.go deleted file mode 100644 index ee8002e..0000000 --- a/output_tests/struct/struct/empty_alias/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeA struct{} - -type typeForTest struct { - F typeA -} diff --git a/output_tests/struct/struct/float32s/json_test.go b/output_tests/struct/struct/float32s/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/float32s/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/float32s/types.go b/output_tests/struct/struct/float32s/types.go deleted file mode 100644 index 5ee59c4..0000000 --- a/output_tests/struct/struct/float32s/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F struct { - F1 float32 - F2 float32 - F3 float32 - } -} diff --git a/output_tests/struct/struct/float64/json_test.go b/output_tests/struct/struct/float64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/float64/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/float64/types.go b/output_tests/struct/struct/float64/types.go deleted file mode 100644 index e7e4639..0000000 --- a/output_tests/struct/struct/float64/types.go +++ /dev/null @@ -1,7 +0,0 @@ -package test - -type typeForTest struct { - F struct { - F float32 - } -} diff --git a/output_tests/struct/struct/float64_alias/json_test.go b/output_tests/struct/struct/float64_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/float64_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/float64_alias/types.go b/output_tests/struct/struct/float64_alias/types.go deleted file mode 100644 index 8c38424..0000000 --- a/output_tests/struct/struct/float64_alias/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeA struct { - F float64 -} - -type typeForTest struct { - F typeA -} diff --git a/output_tests/struct/struct/int32s/json_test.go b/output_tests/struct/struct/int32s/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/int32s/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/int32s/types.go b/output_tests/struct/struct/int32s/types.go deleted file mode 100644 index 8fe6faf..0000000 --- a/output_tests/struct/struct/int32s/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F struct { - F1 int32 - F2 int32 - F3 int32 - } -} diff --git a/output_tests/struct/struct/strings/json_test.go b/output_tests/struct/struct/strings/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/strings/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/strings/types.go b/output_tests/struct/struct/strings/types.go deleted file mode 100644 index a3e403a..0000000 --- a/output_tests/struct/struct/strings/types.go +++ /dev/null @@ -1,9 +0,0 @@ -package test - -type typeForTest struct { - F struct { - F1 string - F2 string - F3 string - } -} diff --git a/output_tests/struct/struct/strings_alias/json_test.go b/output_tests/struct/struct/strings_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/struct/struct/strings_alias/json_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package test - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - - "github.com/davecgh/go-spew/spew" - fuzz "github.com/google/gofuzz" - jsoniter "github.com/json-iterator/go" -) - -func Test_Roundtrip(t *testing.T) { - fz := fuzz.New().MaxDepth(10).NilChance(0.3) - for i := 0; i < 100; i++ { - var before typeForTest - fz.Fuzz(&before) - - jbStd, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with stdlib: %v", err) - } - if len(strings.TrimSpace(string(jbStd))) == 0 { - t.Fatal("stdlib marshal produced empty result and no error") - } - jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal with jsoniter: %v", err) - } - if len(strings.TrimSpace(string(jbIter))) == 0 { - t.Fatal("jsoniter marshal produced empty result and no error") - } - if string(jbStd) != string(jbIter) { - t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", - indent(jbStd, " "), indent(jbIter, " "), dump(before)) - } - - var afterStd typeForTest - err = json.Unmarshal(jbIter, &afterStd) - if err != nil { - t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - var afterIter typeForTest - err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) - if err != nil { - t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", - err, indent(jbIter, " ")) - } - if fingerprint(afterStd) != fingerprint(afterIter) { - t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", - dump(afterStd), dump(afterIter), indent(jbIter, " ")) - } - } -} - -const indentStr = "> " - -func fingerprint(obj interface{}) string { - c := spew.ConfigState{ - SortKeys: true, - SpewKeys: true, - } - return c.Sprintf("%v", obj) -} - -func dump(obj interface{}) string { - cfg := spew.ConfigState{ - Indent: indentStr, - } - return cfg.Sdump(obj) -} - -func indent(src []byte, prefix string) string { - var buf bytes.Buffer - err := json.Indent(&buf, src, prefix, indentStr) - if err != nil { - return fmt.Sprintf("!!! %v", err) - } - return buf.String() -} - -func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) { - t.ReportAllocs() - t.ResetTimer() - - var obj typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&obj) - for i := 0; i < t.N; i++ { - jb, err := fn(obj) - if err != nil { - t.Fatalf("%s failed to marshal:\n input: %s\n error: %v", name, dump(obj), err) - } - _ = jb - } -} - -func benchmarkUnmarshal(t *testing.B, name string, fn func(data []byte, v interface{}) error) { - t.ReportAllocs() - t.ResetTimer() - - var before typeForTest - fz := fuzz.NewWithSeed(0).MaxDepth(10).NilChance(0.3) - fz.Fuzz(&before) - jb, err := json.Marshal(before) - if err != nil { - t.Fatalf("failed to marshal: %v", err) - } - - for i := 0; i < t.N; i++ { - var after typeForTest - err = fn(jb, &after) - if err != nil { - t.Fatalf("%s failed to unmarshal:\n input: %q\n error: %v", name, string(jb), err) - } - } -} - -func BenchmarkStandardMarshal(t *testing.B) { - benchmarkMarshal(t, "stdlib", json.Marshal) -} - -func BenchmarkStandardUnmarshal(t *testing.B) { - benchmarkUnmarshal(t, "stdlib", json.Unmarshal) -} - -func BenchmarkJSONIterMarshalFastest(t *testing.B) { - benchmarkMarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Marshal) -} - -func BenchmarkJSONIterUnmarshalFastest(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-fastest", jsoniter.ConfigFastest.Unmarshal) -} - -func BenchmarkJSONIterMarshalDefault(t *testing.B) { - benchmarkMarshal(t, "jsoniter-default", jsoniter.Marshal) -} - -func BenchmarkJSONIterUnmarshalDefault(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-default", jsoniter.Unmarshal) -} - -func BenchmarkJSONIterMarshalCompatible(t *testing.B) { - benchmarkMarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal) -} - -func BenchmarkJSONIterUnmarshalCompatible(t *testing.B) { - benchmarkUnmarshal(t, "jsoniter-compat", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal) -} diff --git a/output_tests/struct/struct/strings_alias/types.go b/output_tests/struct/struct/strings_alias/types.go deleted file mode 100644 index 6468df3..0000000 --- a/output_tests/struct/struct/strings_alias/types.go +++ /dev/null @@ -1,13 +0,0 @@ -package test - -type typeS string - -type typeA struct { - F1 typeS - F2 typeS - F3 typeS -} - -type typeForTest struct { - F typeA -} diff --git a/type_tests/array_test.go b/type_tests/array_test.go index 7e22922..1a57fea 100644 --- a/type_tests/array_test.go +++ b/type_tests/array_test.go @@ -59,4 +59,5 @@ func init() { ) } -type structEmpty struct{} \ No newline at end of file +type structEmpty struct{} +type arrayAlis [4]stringAlias \ No newline at end of file diff --git a/type_tests/builtin_test.go b/type_tests/builtin_test.go index 9859828..4f809c5 100644 --- a/type_tests/builtin_test.go +++ b/type_tests/builtin_test.go @@ -35,11 +35,14 @@ type boolAlias bool type byteAlias byte type float32Alias float32 type float64Alias float64 +type ptrFloat64Alias *float64 type int8Alias int8 type int16Alias int16 type int32Alias int32 +type ptrInt32Alias *int32 type int64Alias int64 type stringAlias string +type ptrStringAlias *string type uint8Alias uint8 type uint16Alias uint16 type uint32Alias uint32 diff --git a/type_tests/marshaler_string_test.go b/type_tests/marshaler_string_test.go index 8fe1b2e..15e8f4e 100644 --- a/type_tests/marshaler_string_test.go +++ b/type_tests/marshaler_string_test.go @@ -7,9 +7,9 @@ import ( "encoding/json" ) -type stringMarshaler string +type StringMarshaler string -func (m stringMarshaler) encode(str string) string { +func (m StringMarshaler) encode(str string) string { buf := bytes.Buffer{} b64 := base64.NewEncoder(base64.StdEncoding, &buf) if _, err := b64.Write([]byte(str)); err != nil { @@ -21,7 +21,7 @@ func (m stringMarshaler) encode(str string) string { return buf.String() } -func (m stringMarshaler) decode(str string) string { +func (m StringMarshaler) decode(str string) string { if len(str) == 0 { return "" } @@ -35,18 +35,18 @@ func (m stringMarshaler) decode(str string) string { return string(bs) } -func (m stringMarshaler) MarshalJSON() ([]byte, error) { +func (m StringMarshaler) MarshalJSON() ([]byte, error) { return []byte(`"MANUAL__` + m.encode(string(m)) + `"`), nil } -func (m *stringMarshaler) UnmarshalJSON(text []byte) error { - *m = stringMarshaler(m.decode(strings.TrimPrefix(strings.Trim(string(text), `"`), "MANUAL__"))) +func (m *StringMarshaler) UnmarshalJSON(text []byte) error { + *m = StringMarshaler(m.decode(strings.TrimPrefix(strings.Trim(string(text), `"`), "MANUAL__"))) return nil } -var _ json.Marshaler = *new(stringMarshaler) -var _ json.Unmarshaler = new(stringMarshaler) +var _ json.Marshaler = *new(StringMarshaler) +var _ json.Unmarshaler = new(StringMarshaler) func init() { - testCases = append(testCases, (*stringMarshaler)(nil)) + testCases = append(testCases, (*StringMarshaler)(nil)) } \ No newline at end of file diff --git a/type_tests/struct_embedded_test.go b/type_tests/struct_embedded_test.go new file mode 100644 index 0000000..1a53cbc --- /dev/null +++ b/type_tests/struct_embedded_test.go @@ -0,0 +1,220 @@ +package test + +func init() { + testCases = append(testCases, + (*struct { + EmbeddedFloat64 + })(nil), + (*struct { + EmbeddedInt32 + })(nil), + (*struct { + F1 float64 + StringMarshaler + F2 int32 + })(nil), + (*struct { + EmbeddedMapStringString + })(nil), + (*struct { + *EmbeddedFloat64 + })(nil), + (*struct { + *EmbeddedInt32 + })(nil), + (*struct { + *EmbeddedMapStringString + })(nil), + (*struct { + *EmbeddedSliceString + })(nil), + (*struct { + *EmbeddedString + })(nil), + (*struct { + *EmbeddedStruct + })(nil), + (*struct { + EmbeddedSliceString + })(nil), + (*struct { + EmbeddedString + })(nil), + (*struct { + EmbeddedString `json:"othername"` + })(nil), + (*struct { + EmbeddedStruct + })(nil), + (*struct { + F1 float64 + StringTextMarshaler + F2 int32 + })(nil), + (*OverlapDifferentLevels)(nil), + (*IgnoreDeeperLevel)(nil), + (*SameLevel1BothTagged)(nil), + (*SameLevel1NoTags)(nil), + (*SameLevel1Tagged)(nil), + (*SameLevel2BothTagged)(nil), + (*SameLevel2NoTags)(nil), + (*SameLevel2Tagged)(nil), + ) +} + +type EmbeddedFloat64 float64 +type EmbeddedInt32 int32 +type EmbeddedMapStringString map[string]string +type EmbeddedSliceString []string +type EmbeddedString string +type EmbeddedStruct struct { + String string + Int int32 + Float float64 + Struct struct { + X string + } + Slice []string + Map map[string]string +} + +type OverlapDifferentLevelsE1 struct { + F1 int32 +} + +type OverlapDifferentLevelsE2 struct { + F2 string +} + +type OverlapDifferentLevels struct { + OverlapDifferentLevelsE1 + OverlapDifferentLevelsE2 + F1 string +} + +type IgnoreDeeperLevelDoubleEmbedded struct { + F1 int32 `json:"F1"` +} + +type IgnoreDeeperLevelE1 struct { + IgnoreDeeperLevelDoubleEmbedded + F1 int32 +} + +type IgnoreDeeperLevelE2 struct { + F1 int32 `json:"F1"` + IgnoreDeeperLevelDoubleEmbedded +} + +type IgnoreDeeperLevel struct { + IgnoreDeeperLevelE1 + IgnoreDeeperLevelE2 +} + +type SameLevel1BothTaggedE1 struct { + F1 int32 `json:"F1"` +} + +type SameLevel1BothTaggedE2 struct { + F1 int32 `json:"F1"` +} + +type SameLevel1BothTagged struct { + SameLevel1BothTaggedE1 + SameLevel1BothTaggedE2 +} + +type SameLevel1NoTagsE1 struct { + F1 int32 +} + +type SameLevel1NoTagsE2 struct { + F1 int32 +} + +type SameLevel1NoTags struct { + SameLevel1NoTagsE1 + SameLevel1NoTagsE2 +} + +type SameLevel1TaggedE1 struct { + F1 int32 +} + +type SameLevel1TaggedE2 struct { + F1 int32 `json:"F1"` +} + +type SameLevel1Tagged struct { + SameLevel1TaggedE1 + SameLevel1TaggedE2 +} + +type SameLevel2BothTaggedDE1 struct { + F1 int32 `json:"F1"` +} + +type SameLevel2BothTaggedE1 struct { + SameLevel2BothTaggedDE1 +} + +// DoubleEmbedded2 TEST ONLY +type SameLevel2BothTaggedDE2 struct { + F1 int32 `json:"F1"` +} + +// Embedded2 TEST ONLY +type SameLevel2BothTaggedE2 struct { + SameLevel2BothTaggedDE2 +} + +type SameLevel2BothTagged struct { + SameLevel2BothTaggedE1 + SameLevel2BothTaggedE2 +} + +type SameLevel2NoTagsDE1 struct { + F1 int32 +} + +type SameLevel2NoTagsE1 struct { + SameLevel2NoTagsDE1 +} + +type SameLevel2NoTagsDE2 struct { + F1 int32 +} + +type SameLevel2NoTagsE2 struct { + SameLevel2NoTagsDE2 +} + +type SameLevel2NoTags struct { + SameLevel2NoTagsE1 + SameLevel2NoTagsE2 +} + +// DoubleEmbedded1 TEST ONLY +type SameLevel2TaggedDE1 struct { + F1 int32 +} + +// Embedded1 TEST ONLY +type SameLevel2TaggedE1 struct { + SameLevel2TaggedDE1 +} + +// DoubleEmbedded2 TEST ONLY +type SameLevel2TaggedDE2 struct { + F1 int32 `json:"F1"` +} + +// Embedded2 TEST ONLY +type SameLevel2TaggedE2 struct { + SameLevel2TaggedDE2 +} + +type SameLevel2Tagged struct { + SameLevel2TaggedE1 + SameLevel2TaggedE2 +} diff --git a/type_tests/struct_test.go b/type_tests/struct_test.go new file mode 100644 index 0000000..d2bde24 --- /dev/null +++ b/type_tests/struct_test.go @@ -0,0 +1,277 @@ +package test + +func init() { + testCases = append(testCases, + (*struct1Alias)(nil), + (*struct { + F [4]*string + })(nil), + (*struct { + F [4]string + })(nil), + (*struct { + F1 [4]stringAlias + F2 arrayAlis + })(nil), + (*struct { + F1 [4]string + F2 [4]string + F3 [4]string + })(nil), + (*struct { + F [4]struct { + F1 string + F2 string + F3 string + } + })(nil), + (*struct{})(nil), + (*structEmpty)(nil), + (*struct { + Byte1 byte + Byte2 byte + Bool1 bool + Bool2 bool + Int8 int8 + Int16 int16 + Int32 int32 + Int64 int64 + Uint8 uint8 + Uint16 uint16 + Uint32 uint32 + Uint64 uint64 + Float32 float32 + Float64 float64 + String1 string + String2 string + })(nil), + (*struct { + F float64 + })(nil), + (*struct { + F float64Alias + })(nil), + (*struct { + F1 float64 + F2 float64 + F3 float64 + })(nil), + (*struct { + F1 float64Alias + F2 float64Alias + F3 float64Alias + })(nil), + (*struct { + F int32 + })(nil), + (*struct { + F int32Alias + })(nil), + (*struct { + F1 int32 + F2 int32 + F3 int32 + })(nil), + (*struct { + F1 int32Alias + F2 int32Alias + F3 int32Alias + })(nil), + (*struct { + F int64 + })(nil), + (*struct { + F map[int32]*string + })(nil), + (*struct { + F map[int32]string + })(nil), + (*struct { + F map[int32]struct { + F1 string + F2 string + F3 string + } + })(nil), + (*struct { + F map[string]*string + })(nil), + (*struct { + F map[string]string + })(nil), + (*struct { + F map[string]struct { + F1 string + F2 string + F3 string + } + })(nil), + (*struct { + F *float64 + })(nil), + (*struct { + F1 *float64Alias + F2 ptrFloat64Alias + F3 *ptrFloat64Alias + })(nil), + (*struct { + F *int32 + })(nil), + (*struct { + F1 *int32Alias + F2 ptrInt32Alias + F3 *ptrInt32Alias + })(nil), + (*struct { + F **struct{} + })(nil), + (*struct { + F **struct { + F1 string + F2 string + F3 string + } + })(nil), + (*struct { + F *string + })(nil), + (*struct { + F1 *stringAlias + F2 ptrStringAlias + F3 *ptrStringAlias + })(nil), + (*struct { + F *struct{} + })(nil), + (*struct { + F *struct { + F1 string + F2 string + F3 string + } + })(nil), + (*struct { + F1 *float64 + F2 *float64 + F3 *float64 + })(nil), + (*struct { + F1 *int32 + F2 *int32 + F3 *int32 + })(nil), + (*struct { + F1 *string + F2 *string + F3 *string + })(nil), + (*struct { + F []*string + })(nil), + (*struct { + F []string + })(nil), + (*struct { + F1 []stringAlias + F2 stringAlias + })(nil), + (*struct { + F1 []string + F2 []string + F3 []string + })(nil), + (*struct { + F []struct { + F1 string + F2 string + F3 string + } + })(nil), + (*struct { + F string + })(nil), + (*struct { + F stringAlias + })(nil), + (*struct { + F1 string + F2 string + F3 string + })(nil), + (*struct { + F1 stringAlias + F2 stringAlias + F3 stringAlias + })(nil), + (*struct { + F1 struct{} + F2 struct{} + F3 struct{} + })(nil), + (*struct { + F struct{} + })(nil), + (*struct { + F structEmpty + })(nil), + (*struct { + F struct { + F1 float32 + F2 float32 + F3 float32 + } + })(nil), + (*struct { + F struct { + F float32 + } + })(nil), + (*struct { + F struct2 + })(nil), + (*struct { + F struct { + F1 int32 + F2 int32 + F3 int32 + } + })(nil), + (*struct { + F struct { + F1 string + F2 string + F3 string + } + })(nil), + (*struct { + F struct3 + })(nil), + ) +} + +type struct1 struct { + Byte1 byte + Byte2 byte + Bool1 bool + Bool2 bool + Int8 int8 + Int16 int16 + Int32 int32 + Uint8 uint8 + Uint16 uint16 + Uint32 uint32 + Float32 float32 + Float64 float64 + String1 string + String2 string +} +type struct1Alias struct1 + +type struct2 struct { + F float64 +} +type struct3 struct { + F1 stringAlias + F2 stringAlias + F3 stringAlias +} \ No newline at end of file diff --git a/output_tests/struct/anonymous/no_overlap/text_marshal/types.go b/type_tests/text_marshaler_string_test.go similarity index 52% rename from output_tests/struct/anonymous/no_overlap/text_marshal/types.go rename to type_tests/text_marshaler_string_test.go index d8ad178..be68139 100644 --- a/output_tests/struct/anonymous/no_overlap/text_marshal/types.go +++ b/type_tests/text_marshaler_string_test.go @@ -1,16 +1,16 @@ package test import ( - "bytes" - "encoding" - "encoding/base64" "strings" + "encoding" + "bytes" + "encoding/base64" ) -// MarshalerForTest TEST ONLY -type MarshalerForTest string +// StringTextMarshaler TEST ONLY +type StringTextMarshaler string -func encode(str string) string { +func (m StringTextMarshaler) encode(str string) string { buf := bytes.Buffer{} b64 := base64.NewEncoder(base64.StdEncoding, &buf) if _, err := b64.Write([]byte(str)); err != nil { @@ -22,7 +22,7 @@ func encode(str string) string { return buf.String() } -func decode(str string) string { +func (m StringTextMarshaler) decode(str string) string { if len(str) == 0 { return "" } @@ -37,21 +37,15 @@ func decode(str string) string { } // MarshalText TEST ONLY -func (m MarshalerForTest) MarshalText() ([]byte, error) { - return []byte(`MANUAL__` + encode(string(m))), nil +func (m StringTextMarshaler) MarshalText() ([]byte, error) { + return []byte(`MANUAL__` + m.encode(string(m))), nil } // UnmarshalText TEST ONLY -func (m *MarshalerForTest) UnmarshalText(text []byte) error { - *m = MarshalerForTest(decode(strings.TrimPrefix(string(text), "MANUAL__"))) +func (m *StringTextMarshaler) UnmarshalText(text []byte) error { + *m = StringTextMarshaler(m.decode(strings.TrimPrefix(string(text), "MANUAL__"))) return nil } -var _ encoding.TextMarshaler = *new(MarshalerForTest) -var _ encoding.TextUnmarshaler = new(MarshalerForTest) - -type typeForTest struct { - F1 float64 - MarshalerForTest - F2 int32 -} +var _ encoding.TextMarshaler = *new(StringTextMarshaler) +var _ encoding.TextUnmarshaler = new(StringTextMarshaler) \ No newline at end of file