From beb1d9d5e868265d7c7ad8000dbfdd3719190bad Mon Sep 17 00:00:00 2001 From: Neil O'Toole Date: Sun, 3 Oct 2021 20:39:56 -0600 Subject: [PATCH] more equivalence tests --- .gitignore | 1 + jsoncolor_internal_test.go | 30 ++++++++++++++++++++++++++++++ jsoncolor_test.go | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 jsoncolor_internal_test.go diff --git a/.gitignore b/.gitignore index 9594b1c..67b24c1 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ *.iml .idea TODO.md +**/.DS_Store diff --git a/jsoncolor_internal_test.go b/jsoncolor_internal_test.go new file mode 100644 index 0000000..4cbcf14 --- /dev/null +++ b/jsoncolor_internal_test.go @@ -0,0 +1,30 @@ +package jsoncolor + +import ( + "bytes" + stdjson "encoding/json" + "testing" + + "github.com/segmentio/encoding/json" + + "github.com/stretchr/testify/require" +) + +func TestEquivalenceStdlibCode(t *testing.T) { + if codeJSON == nil { + codeInit() + } + + bufStdj := &bytes.Buffer{} + err := stdjson.NewEncoder(bufStdj).Encode(codeStruct) + require.NoError(t, err) + + bufSegmentj := &bytes.Buffer{} + err = json.NewEncoder(bufSegmentj).Encode(codeStruct) + require.NoError(t, err) + require.Equal(t, bufStdj.String(), bufSegmentj.String()) + + bufJ := &bytes.Buffer{} + err = NewEncoder(bufJ).Encode(codeStruct) + require.Equal(t, bufStdj.String(), bufJ.String()) +} diff --git a/jsoncolor_test.go b/jsoncolor_test.go index 9ee9bec..bab1c47 100644 --- a/jsoncolor_test.go +++ b/jsoncolor_test.go @@ -557,8 +557,8 @@ func newSmallStruct() SmallStruct { } } -func TestEquivalence(t *testing.T) { - rec := makeRecords(t, 1)[0] +func TestEquivalenceRecords(t *testing.T) { + rec := makeRecords(t, 10000)[0] bufStdj := &bytes.Buffer{} err := stdjson.NewEncoder(bufStdj).Encode(rec)