-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes_test.go
97 lines (88 loc) · 1.87 KB
/
types_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
package common
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestString(t *testing.T) {
testliteral := "literal"
var i interface{} = String(testliteral)
assert.Equal(t, reflect.Ptr, reflect.ValueOf(i).Kind())
assert.Equal(t, &testliteral, i)
}
func TestStringValue(t *testing.T) {
testliteral := "literal"
teststrptr := &testliteral
var sv interface{} = StringValue(teststrptr)
assert.Equal(t, reflect.String, reflect.ValueOf(sv).Kind())
assert.Equal(t, testliteral, sv)
assert.Equal(t, "", StringValue((*string)(nil)))
}
func TestInt64(t *testing.T) {
var testint int64 = 7
testintptr := Int64(testint)
assert.Equal(t, reflect.Ptr, reflect.ValueOf(testintptr).Kind())
assert.Equal(t, &testint, testintptr)
}
func TestUintValue(t *testing.T) {
var testUintValue uint = 7
testUintPtr := &testUintValue
var uiv interface{} = UintValue(testUintPtr)
assert.Equal(t, reflect.Uint, reflect.ValueOf(uiv).Kind())
assert.Equal(t, testUintValue, uiv)
assert.Equal(t, uint(0), UintValue((*uint)(nil)))
}
func TestStringToBool(t *testing.T) {
testcases := []struct {
teststring string
pass bool
}{
{
teststring: "true",
pass: true,
},
{
teststring: "True",
pass: true,
},
{
teststring: "t",
pass: true,
},
{
teststring: "yEs",
pass: true,
},
{
teststring: "Y",
pass: true,
},
{
teststring: "on",
pass: true,
},
{
teststring: "tr",
pass: false,
},
{
teststring: "nil",
pass: false,
},
{
teststring: "false",
pass: false,
},
{
teststring: "FOOBAR",
pass: false,
},
}
for _, testcase := range testcases {
assert.Equal(t, testcase.pass, StringToBool(testcase.teststring))
}
}
func TestStringEmpty(t *testing.T) {
assert.True(t, StringEmpty(""))
assert.False(t, StringEmpty("NONEMPTY"))
}