-
Notifications
You must be signed in to change notification settings - Fork 191
/
util_test.go
69 lines (59 loc) · 1.89 KB
/
util_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
package cflag_test
import (
"flag"
"testing"
"github.com/gookit/goutil/cflag"
"github.com/gookit/goutil/testutil/assert"
)
func TestAddPrefix(t *testing.T) {
assert.Eq(t, "-a", cflag.AddPrefix("a"))
assert.Eq(t, "--long", cflag.AddPrefix("long"))
assert.Eq(t, "--long", cflag.AddPrefixes("long", nil))
assert.Eq(t, "--long, -l", cflag.AddPrefixes("long", []string{"l"}))
assert.Eq(t, "-l, --long", cflag.AddPrefixes2("long", []string{"l"}, true))
}
func TestIsFlagHelpErr(t *testing.T) {
assert.False(t, cflag.IsFlagHelpErr(nil))
assert.True(t, cflag.IsFlagHelpErr(flag.ErrHelp))
// IsGoodName
assert.True(t, cflag.IsGoodName("name"))
// WrapColorForCode
assert.Eq(t, "hello <mga>keywords</>", cflag.WrapColorForCode("hello `keywords`"))
}
func TestSplitShortcut(t *testing.T) {
assert.Eq(t, []string{"a", "b"}, cflag.SplitShortcut("a,-b"))
assert.Eq(t, []string{"a", "b"}, cflag.SplitShortcut("a, ,-b"))
assert.Eq(t, []string{"ab", "cd"}, cflag.SplitShortcut("-- ab,,-cd"))
}
func TestReplaceShorts(t *testing.T) {
assert.Len(t, cflag.ReplaceShorts([]string{}, map[string]string{
"f": "file",
}), 0)
assert.Eq(t,
[]string{"--file", "./config.ini", "-e"},
cflag.ReplaceShorts([]string{"-f", "./config.ini", "-e"}, map[string]string{
"f": "file",
}),
)
assert.Eq(t,
[]string{"--file", "./config.ini", "-e", "--number", "23"},
cflag.ReplaceShorts([]string{"-f", "./config.ini", "-e", "--number", "23"}, map[string]string{
"f": "file",
"n": "number",
}),
)
assert.Eq(t,
[]string{"--file", "./config.ini", "-e", "--", "-n", "23"},
cflag.ReplaceShorts([]string{"-f", "./config.ini", "-e", "--", "-n", "23"}, map[string]string{
"f": "file",
"n": "number",
}),
)
assert.Eq(t,
[]string{"--file=./config.ini", "-e", "--", "-n", "23"},
cflag.ReplaceShorts([]string{"-f=./config.ini", "-e", "--", "-n", "23"}, map[string]string{
"f": "file",
"n": "number",
}),
)
}