-
Notifications
You must be signed in to change notification settings - Fork 10
/
parser_test.go
69 lines (61 loc) · 1.42 KB
/
parser_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
package querystring
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParser(t *testing.T) {
cond, err := Parse("message: test\\ value AND datetime: [\"2020-01-01T00:00:00\" TO \"2020-12-31T00:00:00\"]")
if err != nil {
t.Errorf("parse return error, %s", err)
return
}
expected := Condition(&AndCondition{
Left: &MatchCondition{
Field: "message",
Value: "test value",
},
Right: &TimeRangeCondition{
Field: "datetime",
Start: pointer("2020-01-01T00:00:00"),
End: pointer("2020-12-31T00:00:00"),
IncludeStart: true,
IncludeEnd: true,
},
})
assert.Equal(t, expected, cond)
}
func TestParserMixedCondition(t *testing.T) {
cond, err := Parse("a: 1 OR (b: 2 and c: 4)")
if err != nil {
t.Errorf("parse return error, %s", err)
return
}
assert.Equal(t, &OrCondition{
Left: &NumberRangeCondition{
Field: "a",
Start: pointer("1"),
End: pointer("1"),
IncludeStart: true,
IncludeEnd: true,
},
Right: &AndCondition{
Left: &NumberRangeCondition{
Field: "b",
Start: pointer("2"),
End: pointer("2"),
IncludeStart: true,
IncludeEnd: true,
},
Right: &NumberRangeCondition{
Field: "c",
Start: pointer("4"),
End: pointer("4"),
IncludeStart: true,
IncludeEnd: true,
},
},
}, cond)
}
func pointer(s string) *string {
return &s
}