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)) }
func TestPutReflect_struct(t *testing.T) { var a1 testStruct = testStruct{42, "hello", 12.5} expected := make([]byte, 18) lex.PutInt(expected, a1.A) lex.PutString(expected[8:], a1.B) lex.PutFloat32(expected[14:], a1.C) actual := make([]byte, 18) lex.PutReflect(actual, a1) assert.True(t, bytes.Equal(expected, actual)) }
func TestReflect_struct(t *testing.T) { var expected testStruct = testStruct{42, "hello", 12.5} var actual testStruct b := make([]byte, 18) lex.PutInt(b, expected.A) lex.PutString(b[8:], expected.B) lex.PutFloat32(b[14:], expected.C) lex.Reflect(b, &actual) assert.Equal(t, expected, actual) }
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) }
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)) }