-
Notifications
You must be signed in to change notification settings - Fork 21
/
external_test.go
52 lines (45 loc) · 1.15 KB
/
external_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
package quamina_test
import (
"testing"
"quamina.net/go/quamina"
)
type fakeFlattener struct {
r []quamina.Field
}
func (f *fakeFlattener) Flatten(_ []byte, _ quamina.SegmentsTreeTracker) ([]quamina.Field, error) {
return f.r, nil
}
func (f *fakeFlattener) Copy() quamina.Flattener {
return &fakeFlattener{r: f.r}
}
// TestNew proves we can actually call New() using With options
func TestNew(t *testing.T) {
_, err := quamina.New(quamina.WithFlattener(&fakeFlattener{}))
if err != nil {
t.Error("qNew: " + err.Error())
}
}
func TestDifferentFlattener(t *testing.T) {
pos := quamina.ArrayPos{Array: 1, Pos: 1}
f := quamina.Field{
Path: []byte{97},
Val: []byte{49},
ArrayTrail: []quamina.ArrayPos{pos},
}
flattener := &fakeFlattener{r: []quamina.Field{f}}
q, err := quamina.New(quamina.WithFlattener(flattener))
if err != nil {
t.Error("q.new: " + err.Error())
}
err = q.AddPattern("xyz", `{"a": [1]}`)
if err != nil {
t.Error("addP: " + err.Error())
}
matches, err := q.MatchesForEvent([]byte(`{"a": 1}`))
if err != nil {
t.Error("m4: " + err.Error())
}
if len(matches) != 1 || matches[0] != "xyz" {
t.Error("missed!")
}
}