reader_test.go 815 B

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