-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_literal_encoder_test.go
More file actions
42 lines (36 loc) · 977 Bytes
/
string_literal_encoder_test.go
File metadata and controls
42 lines (36 loc) · 977 Bytes
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
package bindata
import (
"bytes"
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStringLiteralEncoderBasic(t *testing.T) {
buf := &bytes.Buffer{}
w := newStringLiteralEncoder(buf)
n, err := w.Write([]byte("Hello World!"))
assert.Nil(t, err)
assert.Equal(t, 12, n)
assert.Equal(t, "\\x48\\x65\\x6c\\x6c\\x6f\\x20\\x57\\x6f\\x72\\x6c\\x64\\x21", buf.String())
}
func TestStringLiteralEncoderUnevenNumBytes(t *testing.T) {
var n int
var err error
hexBuf := &bytes.Buffer{}
enc := hex.NewEncoder(hexBuf)
n, err = enc.Write([]byte("Hello World!"))
assert.Nil(t, err)
assert.Equal(t, 12, n)
bites := hexBuf.Bytes()
buf := &bytes.Buffer{}
w := &hexStringLiteralEncoder{
writer: buf,
}
n, err = w.Write(bites[:11])
assert.Nil(t, err)
assert.Equal(t, 11, n)
n, err = w.Write(bites[11:])
assert.Nil(t, err)
assert.Equal(t, 13, n)
assert.Equal(t, "\\x48\\x65\\x6c\\x6c\\x6f\\x20\\x57\\x6f\\x72\\x6c\\x64\\x21", buf.String())
}