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.
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type valueTest struct {
|
|
in string
|
|
out value
|
|
}
|
|
|
|
func (test valueTest) run(t *testing.T) {
|
|
v, err := readValue(strings.NewReader(test.in + "\r\n"))
|
|
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
|
|
|
|
{":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
|
|
}
|
|
|
|
func TestValues(t *testing.T) {
|
|
for _, test := range valueTests {
|
|
test.run(t)
|
|
}
|
|
}
|