-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper_test.go
73 lines (63 loc) · 1.06 KB
/
helper_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package jzon
import (
"io"
"reflect"
"runtime"
"testing"
)
var (
runtimeErrorType = reflect.TypeOf((*runtime.Error)(nil)).Elem()
)
func skipTest(t *testing.T, fmt string, args ...interface{}) {
t.Skipf(fmt, args...)
}
func withIterator(data string, cb func(it *Iterator)) {
it := NewIterator()
defer it.Release()
if data != "" {
it.ResetBytes(localStringToBytes(data))
}
cb(it)
}
type stepByteReader struct {
b string
step int
err error
}
var _ io.Reader = &stepByteReader{}
func (o *stepByteReader) Read(p []byte) (n int, err error) {
if len(p) == 0 {
return 0, nil
}
if len(o.b) == 0 {
if o.err != nil {
return 0, o.err
}
return 0, io.EOF
}
step := o.step
if step == 0 {
step = 1
} else {
if len(p) < step {
step = len(p)
}
}
n = copy(p[:step], o.b)
o.b = o.b[n:]
return n, nil
}
type repeatByteReader struct {
b byte
count int
}
var _ io.Reader = &repeatByteReader{}
func (r *repeatByteReader) Read(p []byte) (n int, err error) {
l := len(p)
for r.count > 0 && n < l {
p[n] = r.b
r.count--
n++
}
return
}