-
Notifications
You must be signed in to change notification settings - Fork 2
/
iterator_null_test.go
43 lines (40 loc) · 966 Bytes
/
iterator_null_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
package jzon
import (
"io"
"testing"
"github.com/stretchr/testify/require"
)
func TestIterator_Null_ReadNull(t *testing.T) {
t.Run("eof", func(t *testing.T) {
withIterator("", func(it *Iterator) {
err := it.ReadNull()
require.Equal(t, io.EOF, err)
})
})
t.Run("invalid first byte", func(t *testing.T) {
withIterator(" a", func(it *Iterator) {
err := it.ReadNull()
require.IsType(t, UnexpectedByteError{}, err)
})
})
t.Run("error 1", func(t *testing.T) {
withIterator(" n", func(it *Iterator) {
err := it.ReadNull()
require.Equal(t, io.EOF, err)
})
})
t.Run("error 2", func(t *testing.T) {
withIterator(" na", func(it *Iterator) {
err := it.ReadNull()
require.IsType(t, UnexpectedByteError{}, err)
})
})
t.Run("valid", func(t *testing.T) {
withIterator(" null ", func(it *Iterator) {
err := it.ReadNull()
require.NoError(t, err)
_, err = it.NextValueType()
require.Equal(t, io.EOF, err)
})
})
}