-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreader_test.go
76 lines (60 loc) · 1.6 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package jsoncommentstrip
import (
"bytes"
"fmt"
"io/ioutil"
"testing"
)
func process(input, expected string) (err error) {
jsonReader := NewReader(bytes.NewReader([]byte(input)))
result, err := ioutil.ReadAll(jsonReader)
if err != nil {
return
}
resultStr := string(result)
if expected != resultStr {
err = fmt.Errorf("Result is not equals expected\nExpected:\n%#v\n\nResult:\n%#v\n\n", expected, resultStr)
}
return
}
func TestWithoutComments(t *testing.T) {
input := "{\n\"one\": 1,\n\"two\": 2,\n\"string\": \"value\"\n}"
err := process(input, input)
if err != nil {
t.Error(err)
}
input = "{\"one\": 1,\"two\": 2,\"string\": \"value\"}"
err = process(input, input)
if err != nil {
t.Error(err)
}
}
func TestSlComment(t *testing.T) {
input := "{\n\"one\": 1, // test //\n\"two\": 2, //test //\r\n\"string\": \"value\"\n//test\n}"
expected := "{\n\"one\": 1, \n\"two\": 2, \r\n\"string\": \"value\"\n\n}"
err := process(input, expected)
if err != nil {
t.Error(err)
}
input = "{// woot\n\"one\": 1, // test //\n\"two\": 2, //test //\r\n\"string\": \"value\"\n//test\n}"
err = process(input, expected)
if err != nil {
t.Error(err)
}
}
func TestMlComment(t *testing.T) {
expected := "{\"one\":1}"
input := "{/* multi\nline\r\ncomment */\"one\":1}"
err := process(input, expected)
if err != nil {
t.Error(err)
}
}
func TestQuotationEscape(t *testing.T) {
expected := "{\"one\": \"a value \\\" // /*woot\"\r\n}"
input := "{/* multi\nline\r\ncomment */\"one\": \"a value \\\" // /*woot\"/* m\nl *///woot\r\n}"
err := process(input, expected)
if err != nil {
t.Error(err)
}
}