v2ray-core/tools/conf/json/reader_test.go

51 lines
844 B
Go
Raw Normal View History

2016-12-14 22:51:03 +00:00
package json_test
import (
"testing"
"bytes"
2016-12-15 14:53:23 +00:00
2016-12-14 22:51:03 +00:00
"v2ray.com/core/testing/assert"
. "v2ray.com/core/tools/conf/json"
)
func TestReader(t *testing.T) {
assert := assert.On(t)
data := []struct {
input string
output string
}{
{
`
content #comment 1
#comment 2
content 2`,
`
content content 2`},
{`content`, `content`},
{" ", " "},
{`con/*abcd*/tent`, "content"},
{`
text // adlkhdf /*
//comment adfkj
text 2*/`, `
text text 2*`},
{`"//"content`, `"//"content`},
{`abcd'//'abcd`, `abcd'//'abcd`},
2016-12-14 23:00:44 +00:00
{`"\""`, `"\""`},
2016-12-15 14:53:23 +00:00
{`\"/*abcd*/\"`, `\"\"`},
2016-12-14 22:51:03 +00:00
}
for _, testCase := range data {
reader := &Reader{
Reader: bytes.NewReader([]byte(testCase.input)),
}
actual := make([]byte, 1024)
n, err := reader.Read(actual)
assert.Error(err).IsNil()
assert.String(string(actual[:n])).Equals(testCase.output)
}
}