-
Notifications
You must be signed in to change notification settings - Fork 8
/
set_test.go
55 lines (50 loc) · 1 KB
/
set_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
package dproxy
import "testing"
func TestSet(t *testing.T) {
v := parseJSON(`{
"items" : [
{
"name": "Bob",
"age": 20
},
{
"name": "Mike",
"age": 23
},
{
"name": "John",
"age": 22
}
]
}`)
names, err := New(v).Q("name").StringArray()
if err != nil {
t.Fatal(err)
} else if !equalStrings(names, []string{"Bob", "Mike", "John"}) {
t.Error("unexpected names:", names)
}
ages, err := New(v).Q("age").Int64Array()
if err != nil {
t.Fatal(err)
} else if !equalInts(ages, []int64{20, 23, 22}) {
t.Error("unexpected ages:", ages)
}
_ = ages
}
func TestSetTypeError(t *testing.T) {
v := parseJSON(`[true, false, 0, true, false]`)
_, err := New(v).ProxySet().BoolArray()
if err == nil {
t.Fatal("should fail")
}
err2, ok := err.(Error)
if !ok {
t.Fatal("err is not Error:", err)
}
if et := err2.ErrorType(); et != Etype {
t.Fatal("unexpected ErrorType:", et)
}
if ea := err2.FullAddress(); ea != "[2]" {
t.Fatal("unexpected FullAddress:", ea)
}
}