-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameter_test.go
54 lines (44 loc) · 1003 Bytes
/
parameter_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
package klash_test
import (
"testing"
"github.com/mota/klash"
)
func TestHelpTag(t *testing.T) {
type TestStruct struct {
Version bool `klash-help:"Print version and exit"`
}
ts := TestStruct{false}
params, err := klash.NewParams(&ts)
if err != nil {
t.Error(err)
return
}
if params.Mapping["version"].Help != "Print version and exit" {
t.Error("Help message is supposed to be filled")
}
}
func TestAliasTag(t *testing.T) {
type TestStruct struct {
Version bool `klash-alias:"v"`
}
ts := TestStruct{false}
params, err := klash.NewParams(&ts)
if err != nil {
t.Error(err)
return
}
if params.Mapping["version"].Alias != "v" {
t.Error("An alias is supposed to be filled")
}
}
func TestBadAliasTag(t *testing.T) {
type TestStruct struct {
Version bool `klash-alias:"v"`
Debug bool `klash-alias:"version"`
}
ts := TestStruct{false, false}
_, err := klash.NewParams(&ts)
if err == nil {
t.Error("Cannot have a same/alias name for two parameters")
}
}