forked from gookit/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_test.go
57 lines (47 loc) · 1.27 KB
/
value_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
package structs_test
import (
"testing"
"github.com/gookit/goutil/structs"
"github.com/gookit/goutil/testutil/assert"
)
func TestNewValue(t *testing.T) {
v := structs.NewValue(true)
assert.True(t, v.Bool())
v.Set("false")
assert.False(t, v.Bool())
// string
v.Set("12, 34")
assert.Eq(t, "12, 34", v.Val())
assert.Eq(t, "12, 34", v.String())
assert.Eq(t, []string{"12", "34"}, v.Strings())
assert.Eq(t, []string{"12", "34"}, v.SplitToStrings())
assert.Eq(t, []int{12, 34}, v.SplitToInts())
// nil
v.Set(nil)
assert.Empty(t, v.Strings())
assert.Empty(t, v.SplitToInts())
assert.Empty(t, v.SplitToStrings())
}
func TestValue_Val(t *testing.T) {
v := structs.Value{V: 23}
assert.Eq(t, 23, v.Val())
assert.Eq(t, 23, v.Int())
assert.Eq(t, int64(23), v.Int64())
assert.Eq(t, float64(23), v.Float64())
assert.Eq(t, "23", v.String())
assert.False(t, v.IsEmpty())
assert.False(t, v.Bool())
v.V = []string{"a", "b"}
assert.Eq(t, []string{"a", "b"}, v.Val())
assert.Eq(t, []string{"a", "b"}, v.Strings())
v.Reset()
assert.Nil(t, v.V)
assert.Nil(t, v.Val())
assert.Nil(t, v.Strings())
assert.True(t, v.IsEmpty())
assert.False(t, v.Bool())
assert.Eq(t, 0, v.Int())
assert.Eq(t, int64(0), v.Int64())
assert.Eq(t, float64(0), v.Float64())
assert.Eq(t, "", v.String())
}