Add memory allocation test

To make sure none is happening
This commit is contained in:
2024-07-30 23:31:54 +02:00
parent f5e263752e
commit ee4f8ecfd6

View File

@@ -67,6 +67,25 @@ func TestGSM7EncodeComplex8nASCIIString(t *testing.T) {
} }
} }
func TestGSM7EncodeDoesNotAllocateMoreThanNecessary(t *testing.T) {
coder := &GSM7Coder{}
input := "Ducks are fucking great, they quacks, O quackers, what the fuck."
buf := bytes.NewBuffer(make([]byte, GSM7EncodesInto(&input)))
buf.Reset()
expected := buf.Cap()
err := coder.Encode(input, buf)
actual := buf.Cap()
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
if actual != expected {
t.Errorf("Expected buffer of size %v, but got %v", expected, actual)
}
}
func TestGSM7EncodeEmptyString(t *testing.T) { func TestGSM7EncodeEmptyString(t *testing.T) {
coder := &GSM7Coder{} coder := &GSM7Coder{}
var buf bytes.Buffer var buf bytes.Buffer