-
Notifications
You must be signed in to change notification settings - Fork 4
/
dec_arr_iter_test.go
46 lines (42 loc) · 823 Bytes
/
dec_arr_iter_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
package jx
import (
"encoding/json"
"io"
"testing"
"github.com/stretchr/testify/require"
)
func TestDecoder_ArrIter(t *testing.T) {
testIter := func(d *Decoder) error {
iter, err := d.ArrIter()
if err != nil {
return err
}
for iter.Next() {
if err := d.Skip(); err != nil {
return err
}
}
if iter.Next() {
panic("BUG")
}
return iter.Err()
}
for _, s := range testArrs {
checker := require.Error
if json.Valid([]byte(s)) {
checker = require.NoError
}
d := DecodeStr(s)
checker(t, testIter(d), s)
}
t.Run("Depth", func(t *testing.T) {
d := DecodeStr(`[`)
// Emulate depth
d.depth = maxDepth
require.ErrorIs(t, testIter(d), errMaxDepth)
})
t.Run("Empty", func(t *testing.T) {
d := DecodeStr(``)
require.ErrorIs(t, testIter(d), io.ErrUnexpectedEOF)
})
}