-
Notifications
You must be signed in to change notification settings - Fork 4
/
ints_test.go
129 lines (109 loc) · 2.39 KB
/
ints_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package flagvar_test
import (
"flag"
"reflect"
"testing"
"github.com/sgreben/flagvar"
)
func TestInts(t *testing.T) {
fv := flagvar.Ints{}
var fs flag.FlagSet
fs.Var(&fv, "ints", "")
err := fs.Parse([]string{"-ints", "123", "-ints", "9090"})
if err != nil {
t.Fail()
}
if !reflect.DeepEqual(fv.Values, []int64{123, 9090}) {
t.Fail()
}
}
func TestIntsBitSize(t *testing.T) {
fv := flagvar.Ints{BitSize: 32}
var fs flag.FlagSet
fs.Var(&fv, "ints", "")
err := fs.Parse([]string{"-ints", "123", "-ints", "9090"})
if err != nil {
t.Fail()
}
if !reflect.DeepEqual(fv.Values, []int64{123, 9090}) {
t.Fail()
}
}
func TestIntsBase(t *testing.T) {
fv := flagvar.Ints{BitSize: 32, Base: 16}
var fs flag.FlagSet
fs.Var(&fv, "ints", "")
err := fs.Parse([]string{"-ints", "F", "-ints", "0"})
if err != nil {
t.Fail()
}
if !reflect.DeepEqual(fv.Values, []int64{15, 0}) {
t.Fail()
}
}
func TestIntsFail(t *testing.T) {
fv := flagvar.Ints{}
var fs flag.FlagSet
fs.Var(&fv, "ints", "")
err := fs.Parse([]string{"-ints", "abc"})
if err == nil {
t.Fail()
}
}
func TestIntsCSV(t *testing.T) {
fv := flagvar.IntsCSV{}
var fs flag.FlagSet
fs.Var(&fv, "ints-csv", "")
err := fs.Parse([]string{"-ints-csv", "123,9492"})
if err != nil {
t.Fail()
}
if !reflect.DeepEqual(fv.Values, []int64{123, 9492}) {
t.Fail()
}
}
func TestIntsCSVBitSize(t *testing.T) {
fv := flagvar.IntsCSV{BitSize: 32}
var fs flag.FlagSet
fs.Var(&fv, "ints-csv", "")
err := fs.Parse([]string{"-ints-csv", "123,9492"})
if err != nil {
t.Fail()
}
if !reflect.DeepEqual(fv.Values, []int64{123, 9492}) {
t.Fail()
}
}
func TestIntsCSVSeparator(t *testing.T) {
fv := flagvar.IntsCSV{Separator: ";"}
var fs flag.FlagSet
fs.Var(&fv, "ints-csv", "")
err := fs.Parse([]string{"-ints-csv", "123;9492"})
if err != nil {
t.Fail()
}
if !reflect.DeepEqual(fv.Values, []int64{123, 9492}) {
t.Fail()
}
}
func TestIntsCSVAccumulate(t *testing.T) {
fv := flagvar.IntsCSV{Accumulate: true}
var fs flag.FlagSet
fs.Var(&fv, "ints-csv", "")
err := fs.Parse([]string{"-ints-csv", "123,9492", "-ints-csv", "9492"})
if err != nil {
t.Fail()
}
if !reflect.DeepEqual(fv.Values, []int64{123, 9492, 9492}) {
t.Fail()
}
}
func TestIntsCSVFail(t *testing.T) {
fv := flagvar.IntsCSV{}
var fs flag.FlagSet
fs.Var(&fv, "ints-csv", "")
err := fs.Parse([]string{"-ints-csv", "third"})
if err == nil {
t.Fail()
}
}