-
Notifications
You must be signed in to change notification settings - Fork 7
/
query_test.go
101 lines (77 loc) · 1.86 KB
/
query_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package cete
import (
"testing"
"time"
"github.com/1lann/msgpack"
)
func TestQuery(t *testing.T) {
if testing.Short() {
t.Parallel()
}
now := time.Now().Round(0) // strip off monatonic time
jason := Person{
Name: "Jason",
City: "Sydney",
Age: 18,
Height: 172.8,
Likes: []string{"go", "js"},
DOB: now,
Data: []byte("hello"),
}
data, err := msgpack.Marshal(jason)
panicNotNil(err)
doc := Document{
data: data,
table: nil,
}
if string(doc.QueryBytes("Data")) != "hello" {
t.Fatal("query should be hello, but isn't")
}
if string(doc.QueryBytes("Age")) != "" {
t.Fatal("query should be empty, but isn't")
}
if string(doc.QueryBytes("Nothing")) != "" {
t.Fatal("query should be empty, but isn't")
}
if doc.QueryFloat64("Height") != 172.8 {
t.Fatal("query should be 172.8, but isn't")
}
if doc.QueryFloat64("Age") != 0 {
t.Fatal("query should be 0, but isn't")
}
if doc.QueryInt("Age") != 18 {
t.Fatal("query should be 18, but isn't")
}
if doc.QueryInt("Name") != 0 {
t.Fatal("query should be 0, but isn't")
}
if doc.QueryInt64("Age") != 18 {
t.Fatal("query should be 18, but isn't")
}
if doc.QueryInt64("Name") != 0 {
t.Fatal("query should be 0, but isn't")
}
if doc.QueryString("Name") != "Jason" {
t.Fatal("query should be Jason, but isn't")
}
if doc.QueryString("Age") != "" {
t.Fatal("query should be empty, but isn't")
}
if doc.QueryTime("DOB") != now {
t.Fatal("query should be now, but isn't")
}
if !doc.QueryTime("Data").IsZero() {
t.Fatal("query should be zero, but isn't")
}
var person Person
panicNotNil(doc.Decode(&person))
if !person.IsSame(jason) {
t.Fatal("person should be Jason, but isn't")
}
if doc.QueryAll("Name")[0] != "Jason" {
t.Fatal("query should be Jason, but isn't")
}
if doc.QueryAll("Nothing") != nil {
t.Fatal("query should be nil, but isn't")
}
}