1
0
mirror of https://github.com/json-iterator/go.git synced 2025-11-29 22:47:28 +02:00

#34 implement NewEncoder

This commit is contained in:
Tao Wen
2017-06-02 18:46:44 +08:00
parent e36f926072
commit 45bbb40a9f
2 changed files with 31 additions and 0 deletions

View File

@@ -31,4 +31,16 @@ func Test_new_decoder(t *testing.T) {
should.Nil(decoder2.Decode(&arr2))
should.Equal([]int{2}, arr2)
should.False(decoder2.More())
}
func Test_new_encoder(t *testing.T) {
should := require.New(t)
buf1 := &bytes.Buffer{}
encoder1 := json.NewEncoder(buf1)
encoder1.Encode([]int{1})
should.Equal("[1]\n", buf1.String())
buf2 := &bytes.Buffer{}
encoder2 := NewEncoder(buf2)
encoder2.Encode([]int{1})
should.Equal("[1]", buf2.String())
}