github.com/neilotoole/jsoncolor@v0.7.2-0.20231115150201-1637fae69be1/jsoncolor_internal_test.go (about)

     1  package jsoncolor
     2  
     3  import (
     4  	"bytes"
     5  	stdjson "encoding/json"
     6  	"testing"
     7  
     8  	"github.com/segmentio/encoding/json"
     9  
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestEquivalenceStdlibCode(t *testing.T) {
    14  	if codeJSON == nil {
    15  		codeInit()
    16  	}
    17  
    18  	bufStdj := &bytes.Buffer{}
    19  	err := stdjson.NewEncoder(bufStdj).Encode(codeStruct)
    20  	require.NoError(t, err)
    21  
    22  	bufSegmentj := &bytes.Buffer{}
    23  	err = json.NewEncoder(bufSegmentj).Encode(codeStruct)
    24  	require.NoError(t, err)
    25  	require.Equal(t, bufStdj.String(), bufSegmentj.String())
    26  
    27  	bufJ := &bytes.Buffer{}
    28  	err = NewEncoder(bufJ).Encode(codeStruct)
    29  	require.Equal(t, bufStdj.String(), bufJ.String())
    30  }