Beispiel #1
0
func BenchmarkPutInt(b *testing.B) {
	v := 64
	bs := make([]byte, 8)
	for n := 0; n < b.N; n++ {
		lex.PutInt(bs, v)
	}
}
Beispiel #2
0
func TestKey_alias(t *testing.T) {
	var a1 aliasedInt = 42

	expected := make([]byte, 8)
	lex.PutInt(expected, int(a1))

	actual, err := lex.Key(a1)
	assert.Nil(t, err)
	assert.True(t, bytes.Equal(expected, actual))
}
Beispiel #3
0
func TestReflect_notptr(t *testing.T) {
	var v, actual int = 42, 0

	b := make([]byte, 8)
	lex.PutInt(b, v)

	lex.Reflect(b, actual)

	assert.Equal(t, 0, actual)
}
Beispiel #4
0
func TestReflect_alias(t *testing.T) {
	var expected, actual aliasedInt = 42, 0

	b := make([]byte, 8)
	lex.PutInt(b, int(expected))

	lex.Reflect(b, &actual)

	assert.Equal(t, expected, actual)
}
Beispiel #5
0
func TestPutReflect_alias(t *testing.T) {
	var a1 aliasedInt = 42

	expected := make([]byte, 8)
	lex.PutInt(expected, int(a1))

	actual := make([]byte, 8)
	lex.PutReflect(actual, a1)

	assert.True(t, bytes.Equal(expected, actual))
}
Beispiel #6
0
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))
}
Beispiel #7
0
func TestReflect_struct_invalid(t *testing.T) {
	var tests = []interface{}{
		&invalidStruct{},
		&struct{}{},
		&time.Time{},
	}
	b := make([]byte, 16)
	lex.PutInt(b, 42) //just something to decode
	for _, tt := range tests {
		err := lex.Reflect(b, tt)
		assert.NotNil(t, err)
	}
}
Beispiel #8
0
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)
}