-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
106 lines (104 loc) · 2.41 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
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
package arg
import (
"strings"
"testing"
)
func TestGetBool(t *testing.T) {
var dst bool
if getBool("x", nil) {
t.Errorf("Should fail with invalid src")
}
if getBool("true", nil) {
t.Errorf("Should fail with invalid dst")
}
if getBool("x", &dst) {
t.Errorf("Should fail with invalid src")
}
if !getBool("true", &dst) {
t.Errorf("Should not fail with vaild src and dst")
}
}
func TestGetInt64(t *testing.T) {
var dst int64
if getInt64("x", nil) {
t.Errorf("Should fail with invalid src")
}
if getInt64("-3", nil) {
t.Errorf("Should fail with invalid dst")
}
if getInt64("x", &dst) {
t.Errorf("Should fail with invalid src")
}
if !getInt64("-3", &dst) {
t.Errorf("Should not fail with vaild src and dst")
}
}
func TestGetUint64(t *testing.T) {
var dst uint64
if getUint64("x", nil) {
t.Errorf("Should fail with invalid src")
}
if getUint64("3", nil) {
t.Errorf("Should fail with invalid dst")
}
if getUint64("x", &dst) {
t.Errorf("Should fail with invalid src")
}
if !getUint64("3", &dst) {
t.Errorf("Should not fail with vaild src and dst")
}
}
func TestGetFloat64(t *testing.T) {
var dst float64
if getFloat64("x", nil) {
t.Errorf("Should fail with invalid src")
}
if getFloat64("3", nil) {
t.Errorf("Should fail with invalid dst")
}
if getFloat64("x", &dst) {
t.Errorf("Should fail with invalid src")
}
if !getFloat64("3", &dst) {
t.Errorf("Should not fail with vaild src and dst")
}
}
func TestGetFloat64Slice(t *testing.T) {
list := strings.Split("1,2,3", ",")
var dst []float64
if getFloat64Slice(list, nil) {
t.Errorf("Should fail with invalid dst")
}
if !getFloat64Slice(list, &dst) {
t.Errorf("Should not fail with vaild src and dst")
}
if len(dst) != 3 {
t.Errorf("String slice should be of length 3")
}
}
func TestGetInt64Slice(t *testing.T) {
list := strings.Split("1,2,3", ",")
var dst []int64
if getInt64Slice(list, nil) {
t.Errorf("Should fail with invalid dst")
}
if !getInt64Slice(list, &dst) {
t.Errorf("Should not fail with vaild src and dst")
}
if len(dst) != 3 {
t.Errorf("String slice should be of length 3")
}
}
func TestGetUint64Slice(t *testing.T) {
list := strings.Split("1,2,3", ",")
var dst []uint64
if getUint64Slice(list, nil) {
t.Errorf("Should fail with invalid dst")
}
if !getUint64Slice(list, &dst) {
t.Errorf("Should not fail with vaild src and dst")
}
if len(dst) != 3 {
t.Errorf("String slice should be of length 3")
}
}