commit 879f576aa57ff479fd304742e1893319a87de80a
parent 002972f789c10d5804f875d7a803c245542ebc9d
Author: francoispqt <francois@parquet.ninja>
Date: Mon, 14 May 2018 08:24:23 +0800
add tests for string encoding
Diffstat:
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/encode_object_test.go b/encode_object_test.go
@@ -300,7 +300,7 @@ func TestEncoderObjectMarshalAPI(t *testing.T) {
})
t.Run("marshal-object-func", func(t *testing.T) {
f := EncodeObjectFunc(func(enc *Encoder) {
- enc.AddStringKey("test", "test")
+ enc.AddStringKeyOmitEmpty("test", "test")
})
r, err := Marshal(f)
assert.Nil(t, err, "Error should be nil")
diff --git a/encode_pool.go b/encode_pool.go
@@ -30,9 +30,6 @@ func init() {
func NewEncoder(w io.Writer) *Encoder {
return &Encoder{w: w}
}
-func newEncoder() *Encoder {
- return &Encoder{}
-}
// BorrowEncoder borrows an Encoder from the pool.
func BorrowEncoder(w io.Writer) *Encoder {
diff --git a/encode_string_test.go b/encode_string_test.go
@@ -80,6 +80,30 @@ func TestEncoderStringEncodeAPI(t *testing.T) {
builder.String(),
"Result of marshalling is different as the one expected")
})
+ t.Run("escaped-sequence3", func(t *testing.T) {
+ str := "hello \b world 𝄞"
+ builder := &strings.Builder{}
+ enc := NewEncoder(builder)
+ err := enc.EncodeString(str)
+ assert.Nil(t, err, "Error should be nil")
+ assert.Equal(
+ t,
+ `"hello \b world 𝄞"`,
+ builder.String(),
+ "Result of marshalling is different as the one expected")
+ })
+ t.Run("escaped-sequence3", func(t *testing.T) {
+ str := "hello \f world 𝄞"
+ builder := &strings.Builder{}
+ enc := NewEncoder(builder)
+ err := enc.EncodeString(str)
+ assert.Nil(t, err, "Error should be nil")
+ assert.Equal(
+ t,
+ "\"hello \\f world 𝄞\"",
+ builder.String(),
+ "Result of marshalling is different as the one expected")
+ })
}
func TestEncoderStringEncodeAPIErrors(t *testing.T) {