From ee4f8ecfd69e51c2d3df3b3359d4eb53a3d888f9 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Tue, 30 Jul 2024 23:31:54 +0200 Subject: [PATCH] Add memory allocation test To make sure none is happening --- encoding/gsm7_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/encoding/gsm7_test.go b/encoding/gsm7_test.go index 9713905..c337ea6 100644 --- a/encoding/gsm7_test.go +++ b/encoding/gsm7_test.go @@ -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) { coder := &GSM7Coder{} var buf bytes.Buffer