| 8 | ) |
| 9 | |
| 10 | func TestWrite(t *testing.T) { |
| 11 | test := func(want string, cmd ...string) { |
| 12 | t.Helper() |
| 13 | buf := &strings.Builder{} |
| 14 | if err := Write(buf, cmd); err != nil { |
| 15 | t.Errorf("write: %s", err) |
| 16 | return |
| 17 | } |
| 18 | have := buf.String() |
| 19 | if have != want { |
| 20 | t.Errorf("have %q, want %q", have, want) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | test("*0\r\n") |
| 25 | test("*1\r\n$0\r\n\r\n", "") |
| 26 | test("*1\r\n$4\r\nPING\r\n", "PING") |
| 27 | test("*3\r\n$4\r\nPING\r\n$1\r\na\r\n$1\r\nb\r\n", "PING", "a", "b") |
| 28 | } |
| 29 | |
| 30 | // https://github.com/antirez/RESP3/blob/master/spec.md |
| 31 | func TestRead(t *testing.T) { |