bytes_test.go 788 B

1234567891011121314151617181920212223242526272829303132333435
  1. package serial_test
  2. import (
  3. "testing"
  4. . "v2ray.com/core/common/serial"
  5. . "v2ray.com/ext/assert"
  6. )
  7. func TestBytesToHex(t *testing.T) {
  8. assert := With(t)
  9. cases := []struct {
  10. input []byte
  11. output string
  12. }{
  13. {input: []byte{}, output: "[]"},
  14. {input: []byte("a"), output: "[61]"},
  15. {input: []byte("abcd"), output: "[61,62,63,64]"},
  16. {input: []byte(";kdfpa;dfkaepr3ira;dlkvn;vopaehra;dkhf"), output: "[3b,6b,64,66,70,61,3b,64,66,6b,61,65,70,72,33,69,72,61,3b,64,6c,6b,76,6e,3b,76,6f,70,61,65,68,72,61,3b,64,6b,68,66]"},
  17. }
  18. for _, test := range cases {
  19. assert(test.output, Equals, BytesToHexString(test.input))
  20. }
  21. }
  22. func TestInt64(t *testing.T) {
  23. assert := With(t)
  24. x := int64(375134875348)
  25. b := Int64ToBytes(x, []byte{})
  26. v := BytesToInt64(b)
  27. assert(x, Equals, v)
  28. }