-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxflags_test.go
90 lines (80 loc) · 1.93 KB
/
xflags_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
package xflags
import (
"errors"
"testing"
"time"
)
func assertBool(t *testing.T, expect, actual bool) bool {
if expect == actual {
return true
}
t.Errorf("expected bool: %v, got: %v", expect, actual)
return false
}
func assertDuration(t *testing.T, expect, actual time.Duration) bool {
if expect == actual {
return true
}
t.Errorf("expected duration: %v, got: %v", expect, actual)
return false
}
func assertFloat64(t *testing.T, expect, actual float64) bool {
if expect == actual {
return true
}
t.Errorf("expected float64: %v, got: %v", expect, actual)
return false
}
func assertInt64(t *testing.T, expect, actual int64) bool {
if expect == actual {
return true
}
t.Errorf("expected int64: %v, got: %v", expect, actual)
return false
}
func assertUint64(t *testing.T, expect, actual uint64) bool {
if expect == actual {
return true
}
t.Errorf("expected uint64: 0x%0X, got: 0x%0X", expect, actual)
return false
}
func assertString(t *testing.T, expect, actual string) bool {
if expect == actual {
return true
}
t.Errorf("expected string: \"%s\", got: \"%s\"", expect, actual)
return false
}
func assertStrings(t *testing.T, expect, actual []string) bool {
if len(expect) != len(actual) {
t.Errorf("expected string slice: %q, got: %q", expect, actual)
return false
}
for i := 0; i < len(expect); i++ {
if expect[i] != actual[i] {
t.Errorf("expected string slice: %q, got: %q", expect, actual)
return false
}
}
return true
}
func parseFlag(flag *Flag, args ...string) error {
_, err := NewCommand("test", "").Flags(flag).Must().Parse(args)
return err
}
func assertFlagParses(t *testing.T, flag *Flag, args ...string) bool {
err := parseFlag(flag, args...)
if err != nil {
t.Error(err)
return false
}
return true
}
func assertErrorAs(t *testing.T, err error, target error) bool {
if errors.As(err, &target) {
return true
}
t.Errorf("expected: %T, got: %T: %v", target, err, err)
return false
}