Exemple #1
0
func BenchmarkPutString(b *testing.B) {
	s := "hello world"
	bs := make([]byte, 12)
	for n := 0; n < b.N; n++ {
		lex.PutString(bs, s)
	}
}
Exemple #2
0
func TestReflect_string(t *testing.T) {
	var expected, actual string = "howdy", ""

	b := make([]byte, 6)
	lex.PutString(b, expected)

	lex.Reflect(b, &actual)

	assert.Equal(t, expected, actual)
}
Exemple #3
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))
}
Exemple #4
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)
}