test and fix parsehashkey
This commit is contained in:
@@ -141,6 +141,7 @@ func parseHashKey(raw []byte) string {
|
||||
}
|
||||
return string(matches[j][1])
|
||||
}
|
||||
return string(matches[i][1])
|
||||
}
|
||||
}
|
||||
return ""
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user