From 262e432344be1513f62ad82caaf2757452a57d3e Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 4 Feb 2026 09:39:49 -0700 Subject: [PATCH] test and fix parsehashkey --- src/adapt.go | 1 + src/adapt_test.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/adapt.go b/src/adapt.go index 14a8dd5..4b9136d 100755 --- a/src/adapt.go +++ b/src/adapt.go @@ -141,6 +141,7 @@ func parseHashKey(raw []byte) string { } return string(matches[j][1]) } + return string(matches[i][1]) } } return "" diff --git a/src/adapt_test.go b/src/adapt_test.go index a29191e..0774760 100644 --- a/src/adapt_test.go +++ b/src/adapt_test.go @@ -3,10 +3,31 @@ package src import ( "bufio" "bytes" + "fmt" "strings" "testing" ) +func TestParseHashKey(t *testing.T) { + cases := map[string]string{ + "+OK\r\n": "+OK", + "+string\r\n": "+string", + "*1\r\n$4\r\nping\r\n": "ping", + "*2\r\n$3\r\nget\r\n$1\r\nx\r\n": "x", + "*2\r\n$3\r\nset\r\n$1\r\nx\r\n$1\r\ny\r\n": "x", + } + + for given, expect := range cases { + given, expect := given, expect + t.Run(fmt.Sprintf("%q", given), func(t *testing.T) { + got := parseHashKey([]byte(given)) + if string(got) != expect { + t.Errorf("expected %q=>%q but got =>%q", given, expect, got) + } + }) + } +} + func TestReadMessage(t *testing.T) { cases := map[string]string{ "ok": "+OK\r\n",