forked from alexkappa/exp
-
Notifications
You must be signed in to change notification settings - Fork 26
/
example_test.go
42 lines (32 loc) · 890 Bytes
/
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
package exp
import (
"fmt"
"net/http"
"net/http/httptest"
"time"
)
func Example() {
conjunction := And(True, True, True)
disjunction := Or(True, False)
negation := Not(False)
complex := Or(And(conjunction, disjunction), negation)
fmt.Printf("%t\n", complex.Eval(nil))
// Output: true
}
func Example_uRL() {
writer := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "http://example.com?event=signup&date=2014-10-03&basket_value=199.90&referrer=https://google.com", nil)
handler := func(w http.ResponseWriter, r *http.Request) {
exp := And(
Match("event", "signup"),
Before("date", time.Now()),
GreaterThan("basket_value", 99.99),
Contains("referrer", "google.com"))
if exp.Eval(r.URL.Query()) {
fmt.Fprintf(w, "Expression evaluates")
}
}
handler(writer, request)
fmt.Println(writer.Body.String())
// Output: Expression evaluates
}