-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment_test.go
65 lines (56 loc) · 905 Bytes
/
comment_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
package json2
import (
"errors"
"io"
"testing"
)
func TestDecodeComment(tb *testing.T) {
data := []byte(`
// example object
{
"a": "b", // first key
/* "c": 4,
/********
d: e, */
"f": [],
}
/*final*/
`)
var d Iterator
i, err := d.Skip(data, 0)
if err != nil {
tb.Errorf("error: %v", err)
}
_, i, err = d.Type(data, i)
if !errors.Is(err, ErrShortBuffer) {
tb.Errorf("wanted end-of-buffer: %v", err)
}
if i != len(data) {
tb.Errorf("wrong index: %d / %d", i, len(data))
}
}
func TestReaderComment(tb *testing.T) {
data := []byte(`
// example object
{
"a": "b", // first key
/* "c": 4,
/********
d: e, */
"f": [],
}
/*final*/
`)
r := NewReader(data, nil)
err := r.Skip()
if err != nil {
tb.Errorf("error: %v", err)
}
tp, err := r.Type()
if !errors.Is(err, io.EOF) {
tb.Errorf("wanted EOF: %v", err)
}
if tp != None {
tb.Errorf("wanted none: %v", tp)
}
}