reader_test.go 844 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package json_test
  2. import (
  3. "testing"
  4. "bytes"
  5. "v2ray.com/core/testing/assert"
  6. . "v2ray.com/core/tools/conf/json"
  7. )
  8. func TestReader(t *testing.T) {
  9. assert := assert.On(t)
  10. data := []struct {
  11. input string
  12. output string
  13. }{
  14. {
  15. `
  16. content #comment 1
  17. #comment 2
  18. content 2`,
  19. `
  20. content content 2`},
  21. {`content`, `content`},
  22. {" ", " "},
  23. {`con/*abcd*/tent`, "content"},
  24. {`
  25. text // adlkhdf /*
  26. //comment adfkj
  27. text 2*/`, `
  28. text text 2*`},
  29. {`"//"content`, `"//"content`},
  30. {`abcd'//'abcd`, `abcd'//'abcd`},
  31. {`"\""`, `"\""`},
  32. {`\"/*abcd*/\"`, `\"\"`},
  33. }
  34. for _, testCase := range data {
  35. reader := &Reader{
  36. Reader: bytes.NewReader([]byte(testCase.input)),
  37. }
  38. actual := make([]byte, 1024)
  39. n, err := reader.Read(actual)
  40. assert.Error(err).IsNil()
  41. assert.String(string(actual[:n])).Equals(testCase.output)
  42. }
  43. }