-
Notifications
You must be signed in to change notification settings - Fork 3
/
strconv_test.go
91 lines (88 loc) · 2.12 KB
/
strconv_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package climate
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestSliceParser(t *testing.T) {
{
var (
in = "true"
want = []bool{true}
)
if got := sliceParser(parseBool)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseBool)(%v) = %v, want %v", in, got, want)
}
}
{
var (
in = "false,true" // no space
want = []bool{false, true}
)
if got := sliceParser(parseBool)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseBool)(%v) = %v, want %v", in, got, want)
}
}
{
var (
in = "1, 2, 3, 4, 5" // with space
want = []int64{1, 2, 3, 4, 5}
)
if got := sliceParser(parseInt64)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseInt64)(%v) = %v, want %v", in, got, want)
}
}
{
var (
in = "4398046511104" // 2^42
want = []int64{4398046511104}
)
if got := sliceParser(parseInt64)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseInt64)(%v) = %v, want %v", in, got, want)
}
}
{
var (
in = "18446744073709551615" // 2^64 - 1
want = []uint64{18446744073709551615}
)
if got := sliceParser(parseUint64)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseUint64)(%v) = %v, want %v", in, got, want)
}
}
{
var (
in = "3.14"
want = []float64{3.14}
)
if got := sliceParser(parseFloat64)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseFloat64)(%v) = %v, want %v", in, got, want)
}
}
{
var (
in = "1.7976931348623157e+308"
want = []float64{1.7976931348623157e+308}
)
if got := sliceParser(parseFloat64)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseFloat64)(%v) = %v, want %v", in, got, want)
}
}
{
var (
in = "a,b,c," // trailing comma
want = []string{"a", "b", "c"}
)
if got := sliceParser(parseString)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseString)(%v) = %v, want %v", in, got, want)
}
}
{
var (
in = "a,b,c,\"d,e\"," // "d,e" is quoted
want = []string{"a", "b", "c", "d,e"}
)
if got := sliceParser(parseString)(in); !cmp.Equal(got, want) {
t.Errorf("sliceParser(parseString)(%v) = %v, want %v", in, got, want)
}
}
}