Explorar el Código

Reorganize output_tests for slices

As I added more and more cases, I found the dir structure hard to
navigate.  The new structure follows how you read a type:

   e.g. []*string -> slice/ptr_string

This exposed some redundant cases and some missing cases, too.
Tim Hockin hace 8 años
padre
commit
f09f778ca9
Se han modificado 78 ficheros con 888 adiciones y 48 borrados
  1. 0 0
      output_tests/slice/bool/json_test.go
  2. 0 0
      output_tests/slice/bool/types.go
  3. 0 0
      output_tests/slice/byte/json_test.go
  4. 0 0
      output_tests/slice/byte/types.go
  5. 0 0
      output_tests/slice/float64/json_test.go
  6. 0 0
      output_tests/slice/float64/types.go
  7. 0 0
      output_tests/slice/int32/json_test.go
  8. 0 0
      output_tests/slice/int32/types.go
  9. 0 0
      output_tests/slice/map/int32_string/json_test.go
  10. 3 0
      output_tests/slice/map/int32_string/types.go
  11. 0 0
      output_tests/slice/map/string_string/json_test.go
  12. 3 0
      output_tests/slice/map/string_string/types.go
  13. 0 0
      output_tests/slice/ptr_bool/json_test.go
  14. 0 0
      output_tests/slice/ptr_bool/types.go
  15. 0 0
      output_tests/slice/ptr_float64/json_test.go
  16. 0 0
      output_tests/slice/ptr_float64/types.go
  17. 0 0
      output_tests/slice/ptr_int32/json_test.go
  18. 0 0
      output_tests/slice/ptr_int32/types.go
  19. 0 0
      output_tests/slice/ptr_map/int32_string/json_test.go
  20. 3 0
      output_tests/slice/ptr_map/int32_string/types.go
  21. 0 0
      output_tests/slice/ptr_map/string_string/json_test.go
  22. 3 0
      output_tests/slice/ptr_map/string_string/types.go
  23. 0 0
      output_tests/slice/ptr_slice/bool/json_test.go
  24. 3 0
      output_tests/slice/ptr_slice/bool/types.go
  25. 0 0
      output_tests/slice/ptr_slice/byte/json_test.go
  26. 3 0
      output_tests/slice/ptr_slice/byte/types.go
  27. 0 0
      output_tests/slice/ptr_slice/float64/json_test.go
  28. 3 0
      output_tests/slice/ptr_slice/float64/types.go
  29. 0 0
      output_tests/slice/ptr_slice/int32/json_test.go
  30. 3 0
      output_tests/slice/ptr_slice/int32/types.go
  31. 0 0
      output_tests/slice/ptr_slice/ptr_string/json_test.go
  32. 3 0
      output_tests/slice/ptr_slice/ptr_string/types.go
  33. 0 0
      output_tests/slice/ptr_slice/string/json_test.go
  34. 3 0
      output_tests/slice/ptr_slice/string/types.go
  35. 0 0
      output_tests/slice/ptr_slice/uint8/json_test.go
  36. 3 0
      output_tests/slice/ptr_slice/uint8/types.go
  37. 0 0
      output_tests/slice/ptr_string/json_test.go
  38. 0 0
      output_tests/slice/ptr_string/types.go
  39. 0 0
      output_tests/slice/ptr_struct_various/json_test.go
  40. 1 3
      output_tests/slice/ptr_struct_various/types.go
  41. 0 0
      output_tests/slice/ptr_uint8/json_test.go
  42. 3 0
      output_tests/slice/ptr_uint8/types.go
  43. 0 0
      output_tests/slice/slice/bool/json_test.go
  44. 0 0
      output_tests/slice/slice/bool/types.go
  45. 0 0
      output_tests/slice/slice/byte/json_test.go
  46. 0 0
      output_tests/slice/slice/byte/types.go
  47. 0 0
      output_tests/slice/slice/float64/json_test.go
  48. 0 0
      output_tests/slice/slice/float64/types.go
  49. 0 0
      output_tests/slice/slice/int32/json_test.go
  50. 0 0
      output_tests/slice/slice/int32/types.go
  51. 0 0
      output_tests/slice/slice/ptr_string/json_test.go
  52. 0 0
      output_tests/slice/slice/ptr_string/types.go
  53. 0 0
      output_tests/slice/slice/string/json_test.go
  54. 0 0
      output_tests/slice/slice/string/types.go
  55. 0 0
      output_tests/slice/slice/uint8/json_test.go
  56. 3 0
      output_tests/slice/slice/uint8/types.go
  57. 139 0
      output_tests/slice/string/json_test.go
  58. 0 0
      output_tests/slice/string/types.go
  59. 139 0
      output_tests/slice/struct_empty/json_test.go
  60. 3 0
      output_tests/slice/struct_empty/types.go
  61. 139 0
      output_tests/slice/struct_empty_alias/json_test.go
  62. 5 0
      output_tests/slice/struct_empty_alias/types.go
  63. 139 0
      output_tests/slice/struct_ptr_string/json_test.go
  64. 5 0
      output_tests/slice/struct_ptr_string/types.go
  65. 139 0
      output_tests/slice/struct_various/json_test.go
  66. 1 3
      output_tests/slice/struct_various/types.go
  67. 139 0
      output_tests/slice/uint8/json_test.go
  68. 0 0
      output_tests/slice/uint8/types.go
  69. 0 3
      output_tests/slices/builtins/float32/types.go
  70. 0 3
      output_tests/slices/builtins/int8/types.go
  71. 0 3
      output_tests/slices/pointers/float32/types.go
  72. 0 3
      output_tests/slices/pointers/int8/types.go
  73. 0 3
      output_tests/slices/slices/int8/types.go
  74. 0 3
      output_tests/slices/slices/struct_empty/types.go
  75. 0 5
      output_tests/slices/slices/struct_ptr_string/types.go
  76. 0 7
      output_tests/slices/slices/struct_ptrs_string/types.go
  77. 0 5
      output_tests/slices/slices/struct_string/types.go
  78. 0 7
      output_tests/slices/slices/struct_strings/types.go

+ 0 - 0
output_tests/map/string/ptr_struct/json_test.go → output_tests/slice/bool/json_test.go


+ 0 - 0
output_tests/slices/builtins/bool/types.go → output_tests/slice/bool/types.go


+ 0 - 0
output_tests/map/string/struct/json_test.go → output_tests/slice/byte/json_test.go


+ 0 - 0
output_tests/slices/builtins/byte/types.go → output_tests/slice/byte/types.go


+ 0 - 0
output_tests/slices/builtins/bool/json_test.go → output_tests/slice/float64/json_test.go


+ 0 - 0
output_tests/slices/builtins/float64/types.go → output_tests/slice/float64/types.go


+ 0 - 0
output_tests/slices/builtins/byte/json_test.go → output_tests/slice/int32/json_test.go


+ 0 - 0
output_tests/slices/builtins/int32/types.go → output_tests/slice/int32/types.go


+ 0 - 0
output_tests/slices/builtins/float32/json_test.go → output_tests/slice/map/int32_string/json_test.go


+ 3 - 0
output_tests/slice/map/int32_string/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []map[int32]string

+ 0 - 0
output_tests/slices/builtins/float64/json_test.go → output_tests/slice/map/string_string/json_test.go


+ 3 - 0
output_tests/slice/map/string_string/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []map[string]string

+ 0 - 0
output_tests/slices/builtins/int32/json_test.go → output_tests/slice/ptr_bool/json_test.go


+ 0 - 0
output_tests/slices/pointers/bool/types.go → output_tests/slice/ptr_bool/types.go


+ 0 - 0
output_tests/slices/builtins/int8/json_test.go → output_tests/slice/ptr_float64/json_test.go


+ 0 - 0
output_tests/slices/pointers/float64/types.go → output_tests/slice/ptr_float64/types.go


+ 0 - 0
output_tests/slices/builtins/string/json_test.go → output_tests/slice/ptr_int32/json_test.go


+ 0 - 0
output_tests/slices/pointers/int32/types.go → output_tests/slice/ptr_int32/types.go


+ 0 - 0
output_tests/slices/builtins/uint8/json_test.go → output_tests/slice/ptr_map/int32_string/json_test.go


+ 3 - 0
output_tests/slice/ptr_map/int32_string/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*map[int32]string

+ 0 - 0
output_tests/slices/pointers/bool/json_test.go → output_tests/slice/ptr_map/string_string/json_test.go


+ 3 - 0
output_tests/slice/ptr_map/string_string/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*map[string]string

+ 0 - 0
output_tests/slices/pointers/float32/json_test.go → output_tests/slice/ptr_slice/bool/json_test.go


+ 3 - 0
output_tests/slice/ptr_slice/bool/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*[]bool

+ 0 - 0
output_tests/slices/pointers/float64/json_test.go → output_tests/slice/ptr_slice/byte/json_test.go


+ 3 - 0
output_tests/slice/ptr_slice/byte/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*[]byte

+ 0 - 0
output_tests/slices/pointers/int32/json_test.go → output_tests/slice/ptr_slice/float64/json_test.go


+ 3 - 0
output_tests/slice/ptr_slice/float64/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*[]float64

+ 0 - 0
output_tests/slices/pointers/int8/json_test.go → output_tests/slice/ptr_slice/int32/json_test.go


+ 3 - 0
output_tests/slice/ptr_slice/int32/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*[]int32

+ 0 - 0
output_tests/slices/pointers/string/json_test.go → output_tests/slice/ptr_slice/ptr_string/json_test.go


+ 3 - 0
output_tests/slice/ptr_slice/ptr_string/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*[]*string

+ 0 - 0
output_tests/slices/slices/bool/json_test.go → output_tests/slice/ptr_slice/string/json_test.go


+ 3 - 0
output_tests/slice/ptr_slice/string/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*[]string

+ 0 - 0
output_tests/slices/slices/byte/json_test.go → output_tests/slice/ptr_slice/uint8/json_test.go


+ 3 - 0
output_tests/slice/ptr_slice/uint8/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*[]uint8

+ 0 - 0
output_tests/slices/slices/float64/json_test.go → output_tests/slice/ptr_string/json_test.go


+ 0 - 0
output_tests/slices/pointers/string/types.go → output_tests/slice/ptr_string/types.go


+ 0 - 0
output_tests/slices/slices/int32/json_test.go → output_tests/slice/ptr_struct_various/json_test.go


+ 1 - 3
output_tests/map/string/struct/types.go → output_tests/slice/ptr_struct_various/types.go

@@ -1,6 +1,6 @@
 package test
 
-type Struct struct {
+type T []*struct {
 	String string
 	Int    int32
 	Float  float64
@@ -10,5 +10,3 @@ type Struct struct {
 	Slice []string
 	Map   map[string]string
 }
-
-type T map[string]Struct

+ 0 - 0
output_tests/slices/slices/int8/json_test.go → output_tests/slice/ptr_uint8/json_test.go


+ 3 - 0
output_tests/slice/ptr_uint8/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []*uint8

+ 0 - 0
output_tests/slices/slices/ptr_string/json_test.go → output_tests/slice/slice/bool/json_test.go


+ 0 - 0
output_tests/slices/slices/bool/types.go → output_tests/slice/slice/bool/types.go


+ 0 - 0
output_tests/slices/slices/string/json_test.go → output_tests/slice/slice/byte/json_test.go


+ 0 - 0
output_tests/slices/slices/byte/types.go → output_tests/slice/slice/byte/types.go


+ 0 - 0
output_tests/slices/slices/struct_empty/json_test.go → output_tests/slice/slice/float64/json_test.go


+ 0 - 0
output_tests/slices/slices/float64/types.go → output_tests/slice/slice/float64/types.go


+ 0 - 0
output_tests/slices/slices/struct_ptr_string/json_test.go → output_tests/slice/slice/int32/json_test.go


+ 0 - 0
output_tests/slices/slices/int32/types.go → output_tests/slice/slice/int32/types.go


+ 0 - 0
output_tests/slices/slices/struct_ptrs_string/json_test.go → output_tests/slice/slice/ptr_string/json_test.go


+ 0 - 0
output_tests/slices/slices/ptr_string/types.go → output_tests/slice/slice/ptr_string/types.go


+ 0 - 0
output_tests/slices/slices/struct_string/json_test.go → output_tests/slice/slice/string/json_test.go


+ 0 - 0
output_tests/slices/slices/string/types.go → output_tests/slice/slice/string/types.go


+ 0 - 0
output_tests/slices/slices/struct_strings/json_test.go → output_tests/slice/slice/uint8/json_test.go


+ 3 - 0
output_tests/slice/slice/uint8/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T [][]uint8

+ 139 - 0
output_tests/slice/string/json_test.go

@@ -0,0 +1,139 @@
+package test
+
+import (
+	"bytes"
+	"encoding/json"
+	"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 < 1000; i++ {
+		var before T
+		fz.Fuzz(&before)
+
+		jbStd, err := json.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with stdlib: %v", err)
+		}
+		jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with jsoniter: %v", err)
+		}
+		if string(jbStd) != string(jbIter) {
+			t.Errorf("marshal expected:\n    %s\ngot:\n    %s\nobj:\n    %s",
+				indent(jbStd, "    "), indent(jbIter, "    "), dump(before))
+		}
+
+		var afterStd T
+		err = json.Unmarshal(jbIter, &afterStd)
+		if err != nil {
+			t.Errorf("failed to unmarshal with stdlib: %v", err)
+		}
+		var afterIter T
+		err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
+		if err != nil {
+			t.Errorf("failed to unmarshal with jsoniter: %v", err)
+		}
+		if fingerprint(afterStd) != fingerprint(afterIter) {
+			t.Errorf("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
+	json.Indent(&buf, src, prefix, indentStr)
+	return buf.String()
+}
+
+func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
+	t.ReportAllocs()
+	t.ResetTimer()
+
+	var obj T
+	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 T
+	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 T
+		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)
+}

+ 0 - 0
output_tests/slices/builtins/string/types.go → output_tests/slice/string/types.go


+ 139 - 0
output_tests/slice/struct_empty/json_test.go

@@ -0,0 +1,139 @@
+package test
+
+import (
+	"bytes"
+	"encoding/json"
+	"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 < 1000; i++ {
+		var before T
+		fz.Fuzz(&before)
+
+		jbStd, err := json.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with stdlib: %v", err)
+		}
+		jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with jsoniter: %v", err)
+		}
+		if string(jbStd) != string(jbIter) {
+			t.Errorf("marshal expected:\n    %s\ngot:\n    %s\nobj:\n    %s",
+				indent(jbStd, "    "), indent(jbIter, "    "), dump(before))
+		}
+
+		var afterStd T
+		err = json.Unmarshal(jbIter, &afterStd)
+		if err != nil {
+			t.Errorf("failed to unmarshal with stdlib: %v", err)
+		}
+		var afterIter T
+		err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
+		if err != nil {
+			t.Errorf("failed to unmarshal with jsoniter: %v", err)
+		}
+		if fingerprint(afterStd) != fingerprint(afterIter) {
+			t.Errorf("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
+	json.Indent(&buf, src, prefix, indentStr)
+	return buf.String()
+}
+
+func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
+	t.ReportAllocs()
+	t.ResetTimer()
+
+	var obj T
+	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 T
+	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 T
+		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)
+}

+ 3 - 0
output_tests/slice/struct_empty/types.go

@@ -0,0 +1,3 @@
+package test
+
+type T []struct{}

+ 139 - 0
output_tests/slice/struct_empty_alias/json_test.go

@@ -0,0 +1,139 @@
+package test
+
+import (
+	"bytes"
+	"encoding/json"
+	"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 < 1000; i++ {
+		var before T
+		fz.Fuzz(&before)
+
+		jbStd, err := json.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with stdlib: %v", err)
+		}
+		jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with jsoniter: %v", err)
+		}
+		if string(jbStd) != string(jbIter) {
+			t.Errorf("marshal expected:\n    %s\ngot:\n    %s\nobj:\n    %s",
+				indent(jbStd, "    "), indent(jbIter, "    "), dump(before))
+		}
+
+		var afterStd T
+		err = json.Unmarshal(jbIter, &afterStd)
+		if err != nil {
+			t.Errorf("failed to unmarshal with stdlib: %v", err)
+		}
+		var afterIter T
+		err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
+		if err != nil {
+			t.Errorf("failed to unmarshal with jsoniter: %v", err)
+		}
+		if fingerprint(afterStd) != fingerprint(afterIter) {
+			t.Errorf("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
+	json.Indent(&buf, src, prefix, indentStr)
+	return buf.String()
+}
+
+func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
+	t.ReportAllocs()
+	t.ResetTimer()
+
+	var obj T
+	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 T
+	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 T
+		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)
+}

+ 5 - 0
output_tests/slice/struct_empty_alias/types.go

@@ -0,0 +1,5 @@
+package test
+
+type A struct{}
+
+type T []A

+ 139 - 0
output_tests/slice/struct_ptr_string/json_test.go

@@ -0,0 +1,139 @@
+package test
+
+import (
+	"bytes"
+	"encoding/json"
+	"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 < 1000; i++ {
+		var before T
+		fz.Fuzz(&before)
+
+		jbStd, err := json.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with stdlib: %v", err)
+		}
+		jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with jsoniter: %v", err)
+		}
+		if string(jbStd) != string(jbIter) {
+			t.Errorf("marshal expected:\n    %s\ngot:\n    %s\nobj:\n    %s",
+				indent(jbStd, "    "), indent(jbIter, "    "), dump(before))
+		}
+
+		var afterStd T
+		err = json.Unmarshal(jbIter, &afterStd)
+		if err != nil {
+			t.Errorf("failed to unmarshal with stdlib: %v", err)
+		}
+		var afterIter T
+		err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
+		if err != nil {
+			t.Errorf("failed to unmarshal with jsoniter: %v", err)
+		}
+		if fingerprint(afterStd) != fingerprint(afterIter) {
+			t.Errorf("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
+	json.Indent(&buf, src, prefix, indentStr)
+	return buf.String()
+}
+
+func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
+	t.ReportAllocs()
+	t.ResetTimer()
+
+	var obj T
+	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 T
+	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 T
+		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)
+}

+ 5 - 0
output_tests/slice/struct_ptr_string/types.go

@@ -0,0 +1,5 @@
+package test
+
+type T []struct {
+	F *string
+}

+ 139 - 0
output_tests/slice/struct_various/json_test.go

@@ -0,0 +1,139 @@
+package test
+
+import (
+	"bytes"
+	"encoding/json"
+	"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 < 1000; i++ {
+		var before T
+		fz.Fuzz(&before)
+
+		jbStd, err := json.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with stdlib: %v", err)
+		}
+		jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with jsoniter: %v", err)
+		}
+		if string(jbStd) != string(jbIter) {
+			t.Errorf("marshal expected:\n    %s\ngot:\n    %s\nobj:\n    %s",
+				indent(jbStd, "    "), indent(jbIter, "    "), dump(before))
+		}
+
+		var afterStd T
+		err = json.Unmarshal(jbIter, &afterStd)
+		if err != nil {
+			t.Errorf("failed to unmarshal with stdlib: %v", err)
+		}
+		var afterIter T
+		err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
+		if err != nil {
+			t.Errorf("failed to unmarshal with jsoniter: %v", err)
+		}
+		if fingerprint(afterStd) != fingerprint(afterIter) {
+			t.Errorf("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
+	json.Indent(&buf, src, prefix, indentStr)
+	return buf.String()
+}
+
+func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
+	t.ReportAllocs()
+	t.ResetTimer()
+
+	var obj T
+	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 T
+	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 T
+		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)
+}

+ 1 - 3
output_tests/map/string/ptr_struct/types.go → output_tests/slice/struct_various/types.go

@@ -1,6 +1,6 @@
 package test
 
-type Struct struct {
+type T []struct {
 	String string
 	Int    int32
 	Float  float64
@@ -10,5 +10,3 @@ type Struct struct {
 	Slice []string
 	Map   map[string]string
 }
-
-type T map[string]*Struct

+ 139 - 0
output_tests/slice/uint8/json_test.go

@@ -0,0 +1,139 @@
+package test
+
+import (
+	"bytes"
+	"encoding/json"
+	"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 < 1000; i++ {
+		var before T
+		fz.Fuzz(&before)
+
+		jbStd, err := json.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with stdlib: %v", err)
+		}
+		jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before)
+		if err != nil {
+			t.Errorf("failed to marshal with jsoniter: %v", err)
+		}
+		if string(jbStd) != string(jbIter) {
+			t.Errorf("marshal expected:\n    %s\ngot:\n    %s\nobj:\n    %s",
+				indent(jbStd, "    "), indent(jbIter, "    "), dump(before))
+		}
+
+		var afterStd T
+		err = json.Unmarshal(jbIter, &afterStd)
+		if err != nil {
+			t.Errorf("failed to unmarshal with stdlib: %v", err)
+		}
+		var afterIter T
+		err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter)
+		if err != nil {
+			t.Errorf("failed to unmarshal with jsoniter: %v", err)
+		}
+		if fingerprint(afterStd) != fingerprint(afterIter) {
+			t.Errorf("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
+	json.Indent(&buf, src, prefix, indentStr)
+	return buf.String()
+}
+
+func benchmarkMarshal(t *testing.B, name string, fn func(interface{}) ([]byte, error)) {
+	t.ReportAllocs()
+	t.ResetTimer()
+
+	var obj T
+	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 T
+	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 T
+		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)
+}

+ 0 - 0
output_tests/slices/builtins/uint8/types.go → output_tests/slice/uint8/types.go


+ 0 - 3
output_tests/slices/builtins/float32/types.go

@@ -1,3 +0,0 @@
-package test
-
-type T []float32

+ 0 - 3
output_tests/slices/builtins/int8/types.go

@@ -1,3 +0,0 @@
-package test
-
-type T []int8

+ 0 - 3
output_tests/slices/pointers/float32/types.go

@@ -1,3 +0,0 @@
-package test
-
-type T []*float32

+ 0 - 3
output_tests/slices/pointers/int8/types.go

@@ -1,3 +0,0 @@
-package test
-
-type T []*int8

+ 0 - 3
output_tests/slices/slices/int8/types.go

@@ -1,3 +0,0 @@
-package test
-
-type T [][]int8

+ 0 - 3
output_tests/slices/slices/struct_empty/types.go

@@ -1,3 +0,0 @@
-package test
-
-type T [][]struct{}

+ 0 - 5
output_tests/slices/slices/struct_ptr_string/types.go

@@ -1,5 +0,0 @@
-package test
-
-type T [][]struct {
-	F1 *string
-}

+ 0 - 7
output_tests/slices/slices/struct_ptrs_string/types.go

@@ -1,7 +0,0 @@
-package test
-
-type T [][]struct {
-	F1 *string
-	F2 *string
-	F3 *string
-}

+ 0 - 5
output_tests/slices/slices/struct_string/types.go

@@ -1,5 +0,0 @@
-package test
-
-type T [][]struct {
-	F1 string
-}

+ 0 - 7
output_tests/slices/slices/struct_strings/types.go

@@ -1,7 +0,0 @@
-package test
-
-type T [][]struct {
-	F1 string
-	F2 string
-	F3 string
-}