rework framer tests

This commit is contained in:
Joel Wetzell
2025-12-24 19:13:04 -06:00
parent e679bf2b46
commit 25f2ec30c2
4 changed files with 176 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ import (
"github.com/jwetzell/showbridge-go/internal/framer"
)
func TestGoodSeparatorFramer(t *testing.T) {
func TestGoodSeparatorFramerDecode(t *testing.T) {
tests := []struct {
name string
framer framer.Framer
@@ -78,3 +78,53 @@ func TestGoodSeparatorFramer(t *testing.T) {
})
}
}
func TestGoodSeparatorFramerEncode(t *testing.T) {
tests := []struct {
name string
framer framer.Framer
input []byte
expected []byte
}{
{
name: "new line separator",
framer: framer.GetFramer("LF"),
input: []byte("Hello"),
expected: []byte("Hello\n"),
},
{
name: "CR separator",
framer: framer.GetFramer("CR"),
input: []byte("Hello"),
expected: []byte("Hello\r"),
},
{
name: "CRLF separator",
framer: framer.GetFramer("CRLF"),
input: []byte("Hello"),
expected: []byte("Hello\r\n"),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
frame := test.framer.Encode(test.input)
if !slices.Equal(frame, test.expected) {
t.Errorf("separator framer got %s, expected %s", frame, test.expected)
}
})
}
}
func TestSeparatorFrameBuffer(t *testing.T) {
framer := framer.GetFramer("LF")
framer.Decode([]byte("Hello\nWorld\nThis is a test\nextra"))
if !slices.Equal(framer.Buffer(), []byte("extra")) {
t.Errorf("separator framer buffer got %s, expected %s", framer.Buffer(), []byte("extra"))
}
framer.Clear()
if !slices.Equal(framer.Buffer(), []byte{}) {
t.Errorf("separator framer buffer got %s, expected empty slice", framer.Buffer())
}
}