-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstarlark_test.go
39 lines (32 loc) · 814 Bytes
/
starlark_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
package main
import (
"testing"
"go.starlark.net/starlark"
"go.starlark.net/syntax"
)
func Benchmark_starlark(b *testing.B) {
thread := &starlark.Thread{Name: "example"}
predeclared := starlark.StringDict{
"greeting": starlark.String("hello"),
"Origin": starlark.String("MOW"),
"Country": starlark.String("RU"),
"Adults": starlark.MakeInt(1),
"Value": starlark.MakeInt(100),
}
expr, err := syntax.ParseExpr("example.star", `(Origin == "MOW" or Country == "RU") and (Value >= 100 or Adults == 1)`, syntax.RetainComments)
if err != nil {
b.Fatal(err)
}
var out interface{}
b.ResetTimer()
for n := 0; n < b.N; n++ {
out, err = starlark.EvalExpr(thread, expr, predeclared)
}
b.StopTimer()
if err != nil {
b.Fatal(err)
}
if !out.(starlark.Bool).Truth() {
b.Fail()
}
}