diff --git a/output_tests/map/int16/string/json_test.go b/output_tests/map/int16/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/int16/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/map/int16/string/types.go b/output_tests/map/int16/string/types.go deleted file mode 100644 index bee52d3..0000000 --- a/output_tests/map/int16/string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[int16]string diff --git a/output_tests/map/int32/string/json_test.go b/output_tests/map/int32/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/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/map/int32/string/types.go b/output_tests/map/int32/string/types.go deleted file mode 100644 index 1c31f19..0000000 --- a/output_tests/map/int32/string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[int32]string diff --git a/output_tests/map/int64/string/json_test.go b/output_tests/map/int64/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/int64/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/map/int64/string/types.go b/output_tests/map/int64/string/types.go deleted file mode 100644 index c5e915d..0000000 --- a/output_tests/map/int64/string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[int64]string diff --git a/output_tests/map/int8/string/json_test.go b/output_tests/map/int8/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/int8/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/map/int8/string/types.go b/output_tests/map/int8/string/types.go deleted file mode 100644 index 7b388ea..0000000 --- a/output_tests/map/int8/string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[int8]string diff --git a/output_tests/map/string/array_string/json_test.go b/output_tests/map/string/array_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/array_string/types.go b/output_tests/map/string/array_string/types.go deleted file mode 100644 index 2fe206e..0000000 --- a/output_tests/map/string/array_string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string][4]string diff --git a/output_tests/map/string/bool/json_test.go b/output_tests/map/string/bool/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/bool/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/map/string/bool/types.go b/output_tests/map/string/bool/types.go deleted file mode 100644 index 0228ada..0000000 --- a/output_tests/map/string/bool/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]bool diff --git a/output_tests/map/string/byte/json_test.go b/output_tests/map/string/byte/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/byte/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/map/string/byte/types.go b/output_tests/map/string/byte/types.go deleted file mode 100644 index 6a29b7c..0000000 --- a/output_tests/map/string/byte/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]byte diff --git a/output_tests/map/string/float64/json_test.go b/output_tests/map/string/float64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/float64/types.go b/output_tests/map/string/float64/types.go deleted file mode 100644 index 1b7e838..0000000 --- a/output_tests/map/string/float64/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]float64 diff --git a/output_tests/map/string/int32/json_test.go b/output_tests/map/string/int32/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/int32/types.go b/output_tests/map/string/int32/types.go deleted file mode 100644 index 9bddb99..0000000 --- a/output_tests/map/string/int32/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]int32 diff --git a/output_tests/map/string/map_string_string/json_test.go b/output_tests/map/string/map_string_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/map_string_string/types.go b/output_tests/map/string/map_string_string/types.go deleted file mode 100644 index 21f6231..0000000 --- a/output_tests/map/string/map_string_string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]map[string]string diff --git a/output_tests/map/string/ptr_array_string/json_test.go b/output_tests/map/string/ptr_array_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/ptr_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/map/string/ptr_array_string/types.go b/output_tests/map/string/ptr_array_string/types.go deleted file mode 100644 index a75c203..0000000 --- a/output_tests/map/string/ptr_array_string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]*[4]string diff --git a/output_tests/map/string/ptr_bool/json_test.go b/output_tests/map/string/ptr_bool/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/ptr_bool/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/map/string/ptr_bool/types.go b/output_tests/map/string/ptr_bool/types.go deleted file mode 100644 index 92f4a6c..0000000 --- a/output_tests/map/string/ptr_bool/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]*bool diff --git a/output_tests/map/string/ptr_float64/json_test.go b/output_tests/map/string/ptr_float64/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/ptr_float64/types.go b/output_tests/map/string/ptr_float64/types.go deleted file mode 100644 index 21773af..0000000 --- a/output_tests/map/string/ptr_float64/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]*float64 diff --git a/output_tests/map/string/ptr_int32/json_test.go b/output_tests/map/string/ptr_int32/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/ptr_int32/types.go b/output_tests/map/string/ptr_int32/types.go deleted file mode 100644 index 8e797e3..0000000 --- a/output_tests/map/string/ptr_int32/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]*int32 diff --git a/output_tests/map/string/ptr_map_string_string/json_test.go b/output_tests/map/string/ptr_map_string_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/ptr_map_string_string/types.go b/output_tests/map/string/ptr_map_string_string/types.go deleted file mode 100644 index bcd4666..0000000 --- a/output_tests/map/string/ptr_map_string_string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]*map[string]string diff --git a/output_tests/map/string/ptr_slice_string/json_test.go b/output_tests/map/string/ptr_slice_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/ptr_slice_string/types.go b/output_tests/map/string/ptr_slice_string/types.go deleted file mode 100644 index 150d0be..0000000 --- a/output_tests/map/string/ptr_slice_string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]*[]string diff --git a/output_tests/map/string/ptr_string/json_test.go b/output_tests/map/string/ptr_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/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/map/string/ptr_string/types.go b/output_tests/map/string/ptr_string/types.go deleted file mode 100644 index d83a03c..0000000 --- a/output_tests/map/string/ptr_string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]*string diff --git a/output_tests/map/string/ptr_struct_various/json_test.go b/output_tests/map/string/ptr_struct_various/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/ptr_struct_various/types.go b/output_tests/map/string/ptr_struct_various/types.go deleted file mode 100644 index 0eca3cf..0000000 --- a/output_tests/map/string/ptr_struct_various/types.go +++ /dev/null @@ -1,14 +0,0 @@ -package test - -type typeA struct { - String string - Int int32 - Float float64 - Struct struct { - X string - } - Slice []string - Map map[string]string -} - -type typeForTest map[string]*typeA diff --git a/output_tests/map/string/ptr_uint8/json_test.go b/output_tests/map/string/ptr_uint8/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/ptr_uint8/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/map/string/ptr_uint8/types.go b/output_tests/map/string/ptr_uint8/types.go deleted file mode 100644 index 4fb3210..0000000 --- a/output_tests/map/string/ptr_uint8/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]*uint8 diff --git a/output_tests/map/string/slice_string/json_test.go b/output_tests/map/string/slice_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/slice_string/types.go b/output_tests/map/string/slice_string/types.go deleted file mode 100644 index 99dc487..0000000 --- a/output_tests/map/string/slice_string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string][]string diff --git a/output_tests/map/string/string/json_test.go b/output_tests/map/string/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/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/map/string/string/types.go b/output_tests/map/string/string/types.go deleted file mode 100644 index 14db5d7..0000000 --- a/output_tests/map/string/string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]string diff --git a/output_tests/map/string/string_alias/json_test.go b/output_tests/map/string/string_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/string_alias/types.go b/output_tests/map/string/string_alias/types.go deleted file mode 100644 index a5552fe..0000000 --- a/output_tests/map/string/string_alias/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type stringAlias string - -type typeForTest map[string]stringAlias diff --git a/output_tests/map/string/struct_empty/json_test.go b/output_tests/map/string/struct_empty/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/struct_empty/types.go b/output_tests/map/string/struct_empty/types.go deleted file mode 100644 index 0ab2a52..0000000 --- a/output_tests/map/string/struct_empty/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]struct{} diff --git a/output_tests/map/string/struct_empty_alias/json_test.go b/output_tests/map/string/struct_empty_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/struct_empty_alias/types.go b/output_tests/map/string/struct_empty_alias/types.go deleted file mode 100644 index 5491638..0000000 --- a/output_tests/map/string/struct_empty_alias/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeA struct{} - -type typeForTest map[string]typeA diff --git a/output_tests/map/string/struct_ptr_string/json_test.go b/output_tests/map/string/struct_ptr_string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/struct_ptr_string/types.go b/output_tests/map/string/struct_ptr_string/types.go deleted file mode 100644 index cfb2fd6..0000000 --- a/output_tests/map/string/struct_ptr_string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type typeForTest map[string]struct { - F *string -} diff --git a/output_tests/map/string/struct_various/json_test.go b/output_tests/map/string/struct_various/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/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/map/string/struct_various/types.go b/output_tests/map/string/struct_various/types.go deleted file mode 100644 index 8fbf9af..0000000 --- a/output_tests/map/string/struct_various/types.go +++ /dev/null @@ -1,12 +0,0 @@ -package test - -type typeForTest map[string]struct { - String string - Int int32 - Float float64 - Struct struct { - X string - } - Slice []string - Map map[string]string -} diff --git a/output_tests/map/string/uint8/json_test.go b/output_tests/map/string/uint8/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string/uint8/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/map/string/uint8/types.go b/output_tests/map/string/uint8/types.go deleted file mode 100644 index 76bd605..0000000 --- a/output_tests/map/string/uint8/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[string]uint8 diff --git a/output_tests/map/string_alias/string/json_test.go b/output_tests/map/string_alias/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string_alias/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/map/string_alias/string/types.go b/output_tests/map/string_alias/string/types.go deleted file mode 100644 index e10daa2..0000000 --- a/output_tests/map/string_alias/string/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type stringAlias string - -type typeForTest map[stringAlias]string diff --git a/output_tests/map/string_alias/string_alias/json_test.go b/output_tests/map/string_alias/string_alias/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/string_alias/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/map/string_alias/string_alias/types.go b/output_tests/map/string_alias/string_alias/types.go deleted file mode 100644 index d50ce50..0000000 --- a/output_tests/map/string_alias/string_alias/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package test - -type stringAlias string - -type typeForTest map[stringAlias]stringAlias diff --git a/output_tests/map/uint16/string/json_test.go b/output_tests/map/uint16/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/uint16/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/map/uint16/string/types.go b/output_tests/map/uint16/string/types.go deleted file mode 100644 index 6fe429c..0000000 --- a/output_tests/map/uint16/string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[uint16]string diff --git a/output_tests/map/uint32/string/json_test.go b/output_tests/map/uint32/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/uint32/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/map/uint32/string/types.go b/output_tests/map/uint32/string/types.go deleted file mode 100644 index 0b107a5..0000000 --- a/output_tests/map/uint32/string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[uint32]string diff --git a/output_tests/map/uint8/string/json_test.go b/output_tests/map/uint8/string/json_test.go deleted file mode 100644 index 3c35ffe..0000000 --- a/output_tests/map/uint8/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/map/uint8/string/types.go b/output_tests/map/uint8/string/types.go deleted file mode 100644 index 5d11b14..0000000 --- a/output_tests/map/uint8/string/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -type typeForTest map[uint8]string diff --git a/type_tests/map_test.go b/type_tests/map_test.go new file mode 100644 index 0000000..614f7bc --- /dev/null +++ b/type_tests/map_test.go @@ -0,0 +1,60 @@ +package test + +func init() { + testCases = append(testCases, + (*map[int8]string)(nil), + (*map[int16]string)(nil), + (*map[int32]string)(nil), + (*map[int64]string)(nil), + (*map[string][4]string)(nil), + (*map[string]bool)(nil), + (*map[string]byte)(nil), + (*map[string]float64)(nil), + (*map[string]int32)(nil), + (*map[string]map[string]string)(nil), + (*map[string]*[4]string)(nil), + (*map[string]*bool)(nil), + (*map[string]*float64)(nil), + (*map[string]*int32)(nil), + (*map[string]*map[string]string)(nil), + (*map[string]*[]string)(nil), + (*map[string]*string)(nil), + (*map[string]*structVarious)(nil), + (*map[string]*uint8)(nil), + (*map[string][]string)(nil), + (*map[string]string)(nil), + (*map[string]stringAlias)(nil), + (*map[string]struct{})(nil), + (*map[string]structEmpty)(nil), + (*map[string]struct { + F *string + })(nil), + (*map[string]struct { + String string + Int int32 + Float float64 + Struct struct { + X string + } + Slice []string + Map map[string]string + })(nil), + (*map[string]uint8)(nil), + (*map[stringAlias]string)(nil), + (*map[stringAlias]stringAlias)(nil), + (*map[uint8]string)(nil), + (*map[uint16]string)(nil), + (*map[uint32]string)(nil), + ) +} + +type structVarious struct { + String string + Int int32 + Float float64 + Struct struct { + X string + } + Slice []string + Map map[string]string +}