forked from francoispqt/gojay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_test.go
45 lines (37 loc) · 955 Bytes
/
encode_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gojay
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
type TestWriterError string
func (t TestWriterError) Write(b []byte) (int, error) {
return 0, errors.New("Test Error")
}
func TestAppendBytes(t *testing.T) {
b := []byte(``)
enc := NewEncoder(nil)
enc.buf = b
enc.AppendBytes([]byte(`true`))
assert.Equal(t, string(enc.buf), `true`, "string(enc.buf) should equal to true")
}
func TestAppendByte(t *testing.T) {
b := []byte(``)
enc := NewEncoder(nil)
enc.buf = b
enc.AppendByte(1)
assert.Equal(t, enc.buf[0], uint8(0x1), "b[0] should equal to 1")
}
func TestAppendString(t *testing.T) {
b := []byte(``)
enc := NewEncoder(nil)
enc.buf = b
enc.AppendString("true")
assert.Equal(t, string(enc.buf), `"true"`, "string(enc.buf) should equal to true")
}
func TestBuf(t *testing.T) {
b := []byte(`test`)
enc := NewEncoder(nil)
enc.buf = b
assert.Equal(t, b, enc.Buf(), "enc.Buf() should equal to b")
}