-
Notifications
You must be signed in to change notification settings - Fork 2
/
iterator_raw_test.go
48 lines (42 loc) · 1.07 KB
/
iterator_raw_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
46
47
48
package jzon
import (
"io"
"testing"
"github.com/stretchr/testify/require"
)
func TestIterator_Raw_ReadRaw(t *testing.T) {
t.Run("eof", func(t *testing.T) {
withIterator("", func(it *Iterator) {
_, err := it.ReadRaw()
require.Equal(t, io.EOF, err)
})
})
t.Run("error", func(t *testing.T) {
withIterator(" + ", func(it *Iterator) {
_, err := it.ReadRaw()
require.IsType(t, UnexpectedByteError{}, err)
})
})
t.Run("no error", func(t *testing.T) {
exp := `{ " " : null }`
data := []byte(" " + exp + " ")
withIterator(localByteToString(data), func(it *Iterator) {
raw, err := it.ReadRaw()
require.NoError(t, err)
require.Equal(t, exp, string(raw))
copy(data, []byte(exp+" ")) // modify content
require.Equal(t, exp, string(raw))
_, err = it.ReadRaw()
require.Equal(t, io.EOF, err)
})
})
}
func TestIterator_Raw_AppendRaw(t *testing.T) {
data := `{}`
withIterator(data, func(it *Iterator) {
prefix := []byte(`test`)
b, err := it.AppendRaw(prefix)
require.NoError(t, err)
require.Equal(t, append(prefix, data...), b)
})
}