-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_test.go
87 lines (79 loc) · 1.57 KB
/
helper_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
package helpers
import (
. "testing"
)
func TestImplode(t *T) {
src := []string{"hello", "world"}
result := "hello world"
if Implode(src, " ") != result {
t.Error("Implode fail")
}
}
func TestSliceEqual(t *T) {
src := []string{"hello", "world"}
eq := []string{"hello", "world"}
neq := []string{"hello", "worl"}
if !SliceEqual(src, eq) {
t.Error("Slice Equal fail")
}
if SliceEqual(src, neq) {
t.Error("Slice Equal fail")
}
}
func TestToHumpCase(t *T) {
src := "hello_world"
result := "helloWorld"
if toHumpCase(src) != result {
t.Error("tohumpcase fail")
}
}
func TestToUnderline(t *T) {
src := "helloWorld"
result := "hello_world"
if toUnderline(src) != result {
t.Error("tounderline fail")
}
src = "HHH"
result = "_h_h_h"
if toUnderline(src) != result {
t.Error("tounderline fail")
}
}
func TestExplode(t *T) {
src := "hello world"
result := []string{"hello", "world"}
if !SliceEqual(Explode(src, " "), result) {
t.Error("Explode fail")
}
}
func TestKeys(t *T) {
src := map[string]interface{}{"hello": "1", "world": "2"}
result := []string{"hello", "world"}
if !SliceEqual(Keys(src), result) {
t.Error("Keys fail")
}
}
func TestP(t *T) {
p := NewP()
p.Set("name", "young")
if p.Get("name") != "young" {
t.Error("set fail")
}
p.Set("age", 15)
if p.Get("age") != 15 {
t.Error("set fail")
}
if !p.Exists("name") {
t.Error("exists fail")
}
if p.Exists("not Exists") {
t.Error("exists fail")
}
if !SliceEqual(p.Keys(), []string{"name", "age"}) {
t.Error("keys fail")
}
p.Del("age")
if p.Exists("age") {
t.Error("del fail")
}
}