1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-19 19:06:43 -05:00
v2fly/common/serial/bytes_test.go

36 lines
788 B
Go
Raw Normal View History

2017-04-26 17:26:42 -04:00
package serial_test
import (
"testing"
. "v2ray.com/core/common/serial"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
2017-04-26 17:26:42 -04:00
)
func TestBytesToHex(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-04-26 17:26:42 -04:00
cases := []struct {
input []byte
output string
}{
{input: []byte{}, output: "[]"},
{input: []byte("a"), output: "[61]"},
{input: []byte("abcd"), output: "[61,62,63,64]"},
{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]"},
}
for _, test := range cases {
2017-10-24 10:15:35 -04:00
assert(test.output, Equals, BytesToHexString(test.input))
2017-04-26 17:26:42 -04:00
}
}
2017-04-28 14:44:28 -04:00
func TestInt64(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-04-28 14:44:28 -04:00
x := int64(375134875348)
b := Int64ToBytes(x, []byte{})
v := BytesToInt64(b)
2017-10-24 10:15:35 -04:00
assert(x, Equals, v)
2017-04-28 14:44:28 -04:00
}