-
Notifications
You must be signed in to change notification settings - Fork 0
/
param_test.go
63 lines (54 loc) · 1.5 KB
/
param_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
package args_test
import "testing"
func TestParamDuplicate(t *testing.T) {
a := getParser()
defer panicHandler(`parameter "a" already defined`, t)
i := 1
a.Def("a", &i)
a.Def("a", &i)
}
func TestParamDuplicateAlias(t *testing.T) {
a := getParser()
defer panicHandler(`synonym "A" clashes with an existing parameter name or synonym`, t)
i := 1
s := ""
a.Def("a", &i).Aka("A")
a.Def("b", &s).Aka("A")
}
func TestParamDuplicateTarget(t *testing.T) {
a := getParser()
defer panicHandler(`target for parameter "b" is already assigned`, t)
i := 1
a.Def("a", &i)
a.Def("b", &i)
}
func TestParamNotPointer(t *testing.T) {
a := getParser()
defer panicHandler(`target for parameter "a" is not a pointer`, t)
i := 1
a.Def("a", i)
}
func TestParamSplit1(t *testing.T) {
a := getParser()
defer panicHandler(`cannot split values of "x" (only arrays and slices parameters can be split)`, t)
var x uint8
a.Def("x", &x).Split("foo")
}
func TestParamSplit2(t *testing.T) {
a := getParser()
defer panicHandler("compilation of split expression \"***\" for parameter \"x\" failed: error parsing regexp: missing argument to repetition operator: `*`", t)
var x []uint8
a.Def("x", &x).Split("***")
}
func TestParamOperator1(t *testing.T) {
a := getParser()
defer panicHandler(`parameter name "--" is the name of an operator`, t)
i := 1
a.Def("--", &i)
}
func TestParamOperator2(t *testing.T) {
a := getParser()
defer panicHandler(`parameter name "include" is the name of an operator`, t)
i := 1
a.Def("include", &i)
}