reader_test.go 795 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. for _, testCase := range data {
  33. reader := &Reader{
  34. Reader: bytes.NewReader([]byte(testCase.input)),
  35. }
  36. actual := make([]byte, 1024)
  37. n, err := reader.Read(actual)
  38. assert.Error(err).IsNil()
  39. assert.String(string(actual[:n])).Equals(testCase.output)
  40. }
  41. }