-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdec_skip_test.go
127 lines (114 loc) · 2.09 KB
/
dec_skip_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package jx
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestSkip_number_in_array(t *testing.T) {
var err error
a := require.New(t)
d := DecodeStr(`[-0.12, "stream"]`)
_, err = d.Elem()
a.NoError(err)
err = d.Skip()
a.NoError(err)
_, err = d.Elem()
a.NoError(err)
if s, _ := d.Str(); s != "stream" {
t.FailNow()
}
}
func TestSkip_string_in_array(t *testing.T) {
d := DecodeStr(`["hello", "stream"]`)
d.Elem()
d.Skip()
d.Elem()
if s, _ := d.Str(); s != "stream" {
t.FailNow()
}
}
func TestSkip_null(t *testing.T) {
d := DecodeStr(`[null , "stream"]`)
d.Elem()
d.Skip()
d.Elem()
if s, _ := d.Str(); s != "stream" {
t.FailNow()
}
}
func TestSkip_true(t *testing.T) {
d := DecodeStr(`[true , "stream"]`)
d.Elem()
d.Skip()
d.Elem()
if s, _ := d.Str(); s != "stream" {
t.FailNow()
}
}
func TestSkip_false(t *testing.T) {
d := DecodeStr(`[false , "stream"]`)
d.Elem()
d.Skip()
d.Elem()
if s, _ := d.Str(); s != "stream" {
t.FailNow()
}
}
func TestSkip_array(t *testing.T) {
d := DecodeStr(`[[1, [2, [3], 4]], "stream"]`)
d.Elem()
d.Skip()
d.Elem()
if s, _ := d.Str(); s != "stream" {
t.FailNow()
}
}
func TestSkip_empty_array(t *testing.T) {
d := DecodeStr(`[ [ ], "stream"]`)
d.Elem()
d.Skip()
d.Elem()
if s, _ := d.Str(); s != "stream" {
t.FailNow()
}
}
func TestSkip_nested(t *testing.T) {
d := DecodeStr(`[ {"a" : [{"stream": "c"}], "d": 102 }, "stream"]`)
if _, err := d.Elem(); err != nil {
t.Fatal(err)
}
require.NoError(t, d.Skip())
if _, err := d.Elem(); err != nil {
t.Fatal(err)
}
s, err := d.Str()
require.NoError(t, err)
require.Equal(t, "stream", s)
}
func TestSkip_simple_nested(t *testing.T) {
d := DecodeStr(`["foo", "bar", "baz"]`)
require.NoError(t, d.Skip())
}
func TestDecoder_Bool(t *testing.T) {
for _, s := range []string{
"tru",
"fals",
"",
"nope",
} {
d := DecodeStr(s)
v, err := d.Bool()
require.False(t, v)
require.Error(t, err)
}
}
func TestDecoder_Null(t *testing.T) {
for _, s := range []string{
"",
"nope",
"nul",
"nil",
} {
d := DecodeStr(s)
require.Error(t, d.Null())
}
}