You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB
Go

package main
import (
"strings"
"testing"
)
10 years ago
type valueTest struct {
in string
out value
10 years ago
}
func (test valueTest) run(t *testing.T) {
v, err := readValue(strings.NewReader(test.in + "\r\n"))
10 years ago
if err != nil {
t.Errorf("valueTest error: %v", err)
}
if v != test.out {
t.Errorf("expected %v, got %v", test.out, v)
}
}
var valueTests = []valueTest{
{"+hello", String("hello")},
{"+one two", String("one two")}, // intermediate space
{"+one two ", String("one two ")}, // trailing space
{"+ one two", String(" one two")}, // leading space
{"-hello", Error("hello")},
{"-one two", Error("one two")}, // intermediate space
{"-one two ", Error("one two ")}, // trailing space
{"- one two", Error(" one two")}, // leading space
10 years ago
{"$0\r\n\r\n", BulkString("")}, // is this even a thing?
{"$1\r\nx\r\n", BulkString("x")},
{"$4\r\netsy\r\n", BulkString("etsy")},
{"$12\r\nSaskatchewan\r\n", BulkString("Saskatchewan")},
{":0", Integer(0)},
{":1", Integer(1)},
{":-1", Integer(-1)},
{":12345", Integer(12345)},
{":-12345", Integer(-12345)},
{":9223372036854775807", Integer(9223372036854775807)}, // int64 max
{":-9223372036854775808", Integer(-9223372036854775808)}, // int64 min
{"+hello\r\n+extra\r\n", String("hello")},
{"+one two\r\n+extra\r\n", String("one two")}, // intermediate space
{"+one two \r\n+extra\r\n", String("one two ")}, // trailing space
{"+ one two\r\n+extra\r\n", String(" one two")}, // leading space
{"-hello\r\n+extra\r\n", Error("hello")},
{"-one two\r\n+extra\r\n", Error("one two")}, // intermediate space
{"-one two \r\n+extra\r\n", Error("one two ")}, // trailing space
{"- one two\r\n+extra\r\n", Error(" one two")}, // leading space
{":0\r\n+extra\r\n", Integer(0)},
{":1\r\n+extra\r\n", Integer(1)},
{":-1\r\n+extra\r\n", Integer(-1)},
{":12345\r\n+extra\r\n", Integer(12345)},
{":-12345\r\n+extra\r\n", Integer(-12345)},
{":9223372036854775807\r\n+extra\r\n", Integer(9223372036854775807)}, // int64 max
{":-9223372036854775808\r\n+extra\r\n", Integer(-9223372036854775808)}, // int64 min
}
func TestValues(t *testing.T) {
for _, test := range valueTests {
10 years ago
test.run(t)
}
}