-
Notifications
You must be signed in to change notification settings - Fork 664
/
map_test.go
75 lines (63 loc) · 1.97 KB
/
map_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
package helper
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/process"
)
func TestProcessMapDel(t *testing.T) {
args := []interface{}{
map[string]interface{}{"foo": "Value1", "bar": "Value2"},
"bar",
}
new := process.New("xiang.helper.MapDel", args...).Run().(map[string]interface{})
_, has := new["bar"]
assert.False(t, has)
assert.Equal(t, "Value1", new["foo"])
}
func TestProcessGetSet(t *testing.T) {
args := []interface{}{
map[string]interface{}{"foo": "Value1"},
"bar",
"Value2",
}
new := process.New("xiang.helper.MapSet", args...).Run().(map[string]interface{})
assert.Equal(t, "Value1", new["foo"])
assert.Equal(t, "Value2", new["bar"])
bar := process.New("xiang.helper.MapGet", new, "bar").Run().(string)
assert.Equal(t, "Value2", bar)
}
func TestProcessMapKeys(t *testing.T) {
args := []interface{}{
map[string]interface{}{"foo": "Value1", "bar": "Value2"},
}
keys := process.New("xiang.helper.MapKeys", args...).Run().([]string)
assert.Contains(t, keys, "foo")
assert.Contains(t, keys, "bar")
}
func TestProcessMapValues(t *testing.T) {
args := []interface{}{
map[string]interface{}{"foo": "Value1", "bar": "Value2"},
}
values := process.New("xiang.helper.MapValues", args...).Run().([]interface{})
assert.Contains(t, values, "Value1")
assert.Contains(t, values, "Value2")
}
func TestProcessMapMultiDel(t *testing.T) {
args := []interface{}{
map[string]interface{}{"foo": "Value1", "bar": "Value2"},
"foo",
"bar",
}
new := process.New("xiang.helper.MapMultiDel", args...).Run().(map[string]interface{})
assert.Nil(t, new["foo"])
assert.Nil(t, new["bar"])
}
func TestProcessMapToArray(t *testing.T) {
arr := process.New("xiang.helper.MapToArray", map[string]interface{}{
"foo": "Value1",
"bar": "Value2",
}).Run().([]map[string]interface{})
assert.Len(t, arr, 2)
assert.True(t, arr[0]["key"] == "foo" || arr[0]["key"] == "bar")
assert.True(t, arr[0]["value"] == "Value1" || arr[0]["value"] == "Value2")
}