github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/jsonfmt/level_0/string_test.go (about)

     1  package test
     2  
     3  import (
     4  	"testing"
     5  	"github.com/stretchr/testify/require"
     6  	"github.com/v2pro/plz/msgfmt/jsonfmt"
     7  	"github.com/v2pro/plz/reflect2"
     8  )
     9  
    10  func Test_string(t *testing.T) {
    11  	should := require.New(t)
    12  	encoder := jsonfmt.EncoderOf(reflect2.TypeOf(""))
    13  	should.Equal(`"hello"`, string(encoder.Encode(nil,nil, reflect2.PtrOf("hello"))))
    14  	should.Equal(`"\nhello中文"`, string(encoder.Encode(nil,nil, reflect2.PtrOf("\nhello中文"))))
    15  	should.Equal(`"\nhello中文h\nello"`, string(encoder.Encode(nil,nil, reflect2.PtrOf("\nhello中文h\nello"))))
    16  	should.Equal(`"\nhello中文h\nello\t"`, string(encoder.Encode(nil,nil, reflect2.PtrOf("\nhello中文h\nello\t"))))
    17  }