Example #1
0
func TestKey(t *testing.T) {
	var a1 int16 = 42
	var a2 float32 = 9.2

	expected := make([]byte, 6)
	lex.PutInt16(expected, a1)
	lex.PutFloat32(expected[2:], a2)

	actual, err := lex.Key(a1, a2)
	assert.Nil(t, err)
	assert.True(t, bytes.Equal(expected, actual))
}
Example #2
0
func TestReflect(t *testing.T) {
	var expected1, actual1 int16 = 42, 0
	var expected2, actual2 float32 = 9.2, 0

	b := make([]byte, 6)
	lex.PutInt16(b, expected1)
	lex.PutFloat32(b[2:], expected2)

	lex.Reflect(b, &actual1)
	lex.Reflect(b[2:], &actual2)

	assert.Equal(t, expected1, actual1)
	assert.Equal(t, expected2, actual2)
}
Example #3
0
func TestPutReflect(t *testing.T) {
	var a1 int16 = 42
	var a2 float32 = 9.2

	expected := make([]byte, 6)
	lex.PutInt16(expected, a1)
	lex.PutFloat32(expected[2:], a2)

	actual := make([]byte, 6)
	lex.PutReflect(actual, a1)
	lex.PutReflect(actual[2:], a2)

	assert.True(t, bytes.Equal(expected, actual))
}