-
Notifications
You must be signed in to change notification settings - Fork 1
/
capture_test.go
66 lines (57 loc) · 1.14 KB
/
capture_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
package schema
import "testing"
func TestCapture_Simple(t *testing.T) {
data := dataFromJSON(t, `{
"id": 12,
"messages": [
{
"sender_id": 12,
"text": "hi"
},
{
"sender_id": 12,
"text": "Hello World"
},
{
"sender_id": 12,
"text": "Moin Moin"
}
]
}`)
userID := Capture("user_id")
err := Match(Map{
"id": userID,
"messages": ArrayEach(Map{
"sender_id": userID,
"text": IsString,
}),
}, data)
if err != nil {
t.Fatal(err)
}
if !userID.Equals(12) {
t.Fatalf("userID is not 12 but %v:%T", userID.CapturedValue(), userID.CapturedValue())
}
}
func TestCapture(t *testing.T) {
data := dataFromJSON(t, `{
"id": 12,
"relationship": [42, 12],
"messages": [{"sender_id": 12, "text": "hi"}]
}`)
userID := Capture("user_id")
err := Match(Map{
"id": userID,
"relationship": ArrayUnordered(userID, IsInteger),
"messages": Array(Map{
"sender_id": userID,
"text": IsString,
}),
}, data)
if err != nil {
t.Fatal(err)
}
if !userID.Equals(12) {
t.Fatalf("userID is not 12 but %v:%T", userID.CapturedValue(), userID.CapturedValue())
}
}