-
Notifications
You must be signed in to change notification settings - Fork 4
/
null_test.go
71 lines (64 loc) · 1.33 KB
/
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
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
package jx
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestWriteNull(t *testing.T) {
testEncoderModes(t, func(e *Encoder) {
e.Null()
}, "null")
}
func TestDecodeNullArrayElement(t *testing.T) {
should := require.New(t)
iter := DecodeStr(`[null,"a"]`)
should.True(iter.Elem())
should.NoError(iter.Null())
should.True(iter.Elem())
s, err := iter.Str()
should.NoError(err)
should.Equal("a", s)
}
func TestDecodeNullString(t *testing.T) {
should := require.New(t)
iter := DecodeStr(`[null,"a"]`)
should.True(iter.Elem())
should.NoError(iter.Null())
should.True(iter.Elem())
s, err := iter.Str()
should.NoError(err)
should.Equal("a", s)
}
func TestDecodeNullSkip(t *testing.T) {
iter := DecodeStr(`[null,"a"]`)
iter.Elem()
iter.Skip()
iter.Elem()
if s, _ := iter.Str(); s != "a" {
t.FailNow()
}
}
func TestNullError(t *testing.T) {
a := require.New(t)
var (
b = [4]byte{'n', 'u', 'l', 'l'}
valid = b
)
for i := range b {
// Reset buffer.
b = valid
for c := byte(0); c < 255; c++ {
// Skip expected value.
if valid[i] == c {
continue
}
// Skip space as first character.
if i == 0 && spaceSet[c] == 1 {
continue
}
b[i] = c
var token *badTokenErr
a.ErrorAs(DecodeBytes(b[:]).Null(), &token)
a.Equalf(c, token.Token, "%c != %c (%q)", c, token.Token, b)
}
}
}