-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvalues_test.go
91 lines (84 loc) · 1.7 KB
/
values_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 cli
import (
"reflect"
"testing"
)
func TestValues_Set_comma_separated(t *testing.T) {
tt := []struct {
name string
setup func() Getter
value string
want interface{}
}{
{
name: "bools",
setup: func() Getter {
var v boolValues
return &v
},
value: "true,y,F,no,T",
want: []bool{true, true, false, false, true},
},
{
name: "strings",
setup: func() Getter {
var v stringValues
return &v
},
value: "a,b,1337,true,e",
want: []string{"a", "b", "1337", "true", "e"},
},
{
name: "ints",
setup: func() Getter {
var v intValues
return &v
},
value: "0,-7331,1337,0xABC,0b10101110",
want: []int{0, -7331, 1337, 0xABC, 0b10101110},
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
v := tc.setup()
if err := v.Set(tc.value); err != nil {
t.Fatalf("Set(%q): failed to set the value", tc.value)
}
got := v.Get()
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("Set(%q): got = %#v, want = %#v", tc.value, got, tc.want)
}
})
}
}
func TestValues_String(t *testing.T) {
tt := []struct {
name string
value Value
want string
}{
{
name: "bools",
value: &boolValues{true, true, false, false, true},
want: "true,true,false,false,true",
},
{
name: "strings",
value: &stringValues{"a", "b", "1337", "true", "e"},
want: "a,b,1337,true,e",
},
{
name: "ints",
value: &intValues{0, -7331, 1337, 0xABC, 0b10101110},
want: "0,-7331,1337,2748,174",
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got := tc.value.String()
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("String(): got = %q, want = %q", got, tc.want)
}
})
}
}