github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/jsonfmt/level_0/bytes_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 "github.com/v2pro/plz/msgfmt/jsonfmt" 6 "github.com/v2pro/plz/test" 7 "github.com/v2pro/plz/countlog" 8 "github.com/v2pro/plz/test/must" 9 ) 10 11 func Test_bytes(t *testing.T) { 12 t.Run("simple", test.Case(func(ctx *countlog.Context) { 13 must.Equal(`"hello"`, jsonfmt.MarshalToString([]byte("hello"))) 14 })) 15 t.Run("unicode", test.Case(func(ctx *countlog.Context) { 16 must.Equal(`"\xe4\xb8\xad\xe6\x96\x87"`, jsonfmt.MarshalToString([]byte("中文"))) 17 })) 18 t.Run("unicode and control char", test.Case(func(ctx *countlog.Context) { 19 must.Equal(`"\xe4\xb8\xad\n\xe6\x96\x87"`, jsonfmt.MarshalToString([]byte("中\n文"))) 20 })) 21 }