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
| package serial_test
|
| import (
| "bytes"
| "strings"
| "testing"
|
| "github.com/v2fly/v2ray-core/v5/infra/conf/serial"
| )
|
| func TestLoaderError(t *testing.T) {
| testCases := []struct {
| Input string
| Output string
| }{
| {
| Input: `{
| "log": {
| // abcd
| 0,
| "loglevel": "info"
| }
| }`,
| Output: "line 4 char 6",
| },
| {
| Input: `{
| "log": {
| // abcd
| "loglevel": "info",
| }
| }`,
| Output: "line 5 char 5",
| },
| {
| Input: `{
| "port": 1,
| "inbounds": [{
| "protocol": "test"
| }]
| }`,
| Output: "parse json config",
| },
| {
| Input: `{
| "inbounds": [{
| "port": 1,
| "listen": 0,
| "protocol": "test"
| }]
| }`,
| Output: "line 1 char 1",
| },
| }
| for _, testCase := range testCases {
| reader := bytes.NewReader([]byte(testCase.Input))
| _, err := serial.LoadJSONConfig(reader)
| errString := err.Error()
| if !strings.Contains(errString, testCase.Output) {
| t.Error("unexpected output from json: ", testCase.Input, ". expected ", testCase.Output, ", but actually ", errString)
| }
| }
| }
|
|