Repository navigation
Expand file tree
/
Copy patharray_test.go
More file actions
138 lines (111 loc) · 2.32 KB
/
Copy patharray_test.go
File metadata and controls
138 lines (111 loc) · 2.32 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package phpgo
import (
"encoding/json"
"fmt"
"testing"
)
//目前只测试了 int ,bool,string
func TestIn(t *testing.T) {
var array = Array{"a",1,true,}
var arrmap = make(ArrayMap,3)
arrmap["name"] = "hisheng"
arrmap["age"] = 31
arrmap["height"] = 173.5
array = append(array,arrmap)
//fmt.Println(array)
array = array.Push("sss")
//fmt.Println(array)
f := ArrayMap{"girlfriend":"xiaomei"}
array = append(array,f)
//fmt.Println(array)
array = array.Push(ArrayMap{"dad":"gang"})
//fmt.Println(array)
if !array.In("a") {
t.Fatal("in_array failed ", array.In("a"))
}
if !array.In(1) {
t.Fatal("in_array failed 1")
}
if array.In("1") {
t.Fatal("in_array failed 1")
}
if !array.In(true) {
t.Fatal("in_array failed true")
}
if !array.In("hisheng") {
t.Fatal("hisheng failed true")
}
if !array.In("xiaomei") {
t.Fatal("xiaomei failed true")
}
if !array.In("gang") {
t.Fatal("gang failed true")
}
if !array.In("sss") {
t.Fatal("sss failed true")
}
}
func TestShift(t *testing.T) {
var array = Array{"a",1,true}
if array.Pop() != true {
t.Fatal("pop failed true")
}
if array.Pop() != 1 {
t.Fatal("in_array failed 1")
}
if array.Pop() != "a"{
t.Fatal("in_array failed a")
}
}
func TestPop(t *testing.T) {
var array = Array{"a",1,true,"2"}
if array.Pop() != "2" {
t.Fatal("pop failed 2")
}
if array.Pop() != true {
t.Fatal("in_array failed true")
}
if array.Pop() != 1 {
t.Fatal("in_array failed 1")
}
if array.Pop() != "a" {
t.Fatal("in_array failed a")
}
if array.Pop() != nil{
t.Fatal("in_array failed nil")
}
}
func TestCount(t *testing.T) {
var array = Array{"a",1,true}
if array.Count() != 3 {
t.Fatal("pop failed 3")
}
var array1 = Array{}
if array1.Count() != 0 {
t.Fatal("in_array failed 0")
}
}
func TestPush(t *testing.T) {
var array = Array{"a",1,true}
array.Push("aa")
if array.Pop() != "aa"{
t.Fatal("push failed aa")
}
var array1 = Array{}
array1.Push("ss",1)
if array1.Pop() != 1 {
t.Fatal("push failed 1")
}
if array1.Pop() != "ss" {
t.Fatal("push failed ss")
}
}
func TestJsonEncode(t *testing.T) {
var array = Array{"a",1,true,ArrayMap{"dad":"gga"}}
fmt.Println(array)
fmt.Println(array.JsonEncode())
j, _ := json.Marshal(array)
fmt.Println(string(j))
fmt.Println(JsonDecode(string(j)))
//t.Fatal("test")
}