-
Notifications
You must be signed in to change notification settings - Fork 52
/
example_test.go
60 lines (56 loc) · 1.26 KB
/
example_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
package yql_test
import (
"fmt"
"github.com/caibirdme/yql"
)
func ExampleMatch() {
rawYQL := `name='deen' and age>=23 and (hobby in ('soccer', 'swim') or score>90)`
result, _ := yql.Match(rawYQL, map[string]interface{}{
"name": "deen",
"age": 23,
"hobby": "basketball",
"score": int64(100),
})
fmt.Println(result)
rawYQL = `score ∩ (7,1,9,5,3)`
result, _ = yql.Match(rawYQL, map[string]interface{}{
"score": []int64{3, 100, 200},
})
fmt.Println(result)
rawYQL = `score in (7,1,9,5,3)`
result, _ = yql.Match(rawYQL, map[string]interface{}{
"score": []int64{3, 5, 2},
})
fmt.Println(result)
rawYQL = `score.sum() > 10`
result, _ = yql.Match(rawYQL, map[string]interface{}{
"score": []int{1, 2, 3, 4, 5},
})
fmt.Println(result)
//Output:
//true
//true
//false
//true
}
func ExampleRule() {
rawYQL := `name='deen' and age>=23 and (hobby in ('soccer', 'swim') or score>90)`
ruler, _ := yql.Rule(rawYQL)
result, _ := ruler.Match(map[string]interface{}{
"name": "deen",
"age": 23,
"hobby": "basketball",
"score": int64(100),
})
fmt.Println(result)
result, _ = ruler.Match(map[string]interface{}{
"name": "deen",
"age": 23,
"hobby": "basketball",
"score": int64(90),
})
fmt.Println(result)
//Output:
//true
//false
}