-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader_test.go
53 lines (43 loc) · 1.14 KB
/
reader_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
package json
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReader(t *testing.T) {
var r Reader
for _, data := range []string{
"null", "true", "false",
"1", "1.1", "1e1", "+1", "-1", "-1.4", "0x1p+1", "-0x1p-2", "0x3", "0xf", "0XF",
`""`, `"a"`, `"abc def"`, `"a\"b\nc\td"`,
"[]", "[1, 2, 3]", `[null, "str"]`,
"{}", `{"key":"val"}`, `{"k": "v", "k2": 3, "k3": [], "k4": {}, "k5": null}`,
} {
r.Reset([]byte(data), nil)
raw, err := r.Raw()
if !assert.NoError(t, err) || !assert.Equal(t, []byte(data), raw) {
t.Logf("data: %q", data)
}
}
}
func TestReaderDecodeString(t *testing.T) {
var r Reader
for j, data := range []string{
`""`, `"a"`, `"a\"b\nc\tde\"f\\g"`,
// `"\xab\xac\xf3"`,
`"\u00ab\u00ac\u00f3"`,
`"\u0100\u017e"`,
// `"\U00e4b896\U00e7958c"`,
} {
r.Reset([]byte(data), nil)
s, err := r.DecodeString(nil)
if !assert.NoError(t, err) || !assert.Equal(t, len(data), r.i) {
t.Logf("pos: %d (%[1]x) data: %d %q", r.i, j, data)
continue
}
var q string
err = json.Unmarshal([]byte(data), &q)
assert.NoError(t, err)
assert.Equal(t, q, string(s))
}
}