-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlift_test.go
51 lines (46 loc) · 1.09 KB
/
lift_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
package expr
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLiftLiterals(t *testing.T) {
tests := []struct {
name string
expr string
expectedStr string
expectedArgs map[string]any
}{
{
name: "basic case",
expr: `event.name == "test/yolo"`,
expectedStr: "event.name == vars.a",
expectedArgs: map[string]any{
"a": "test/yolo",
},
},
{
name: "basic case with single quotes",
expr: `event.name == 'test/yolo'`,
expectedStr: "event.name == vars.a",
expectedArgs: map[string]any{
"a": "test/yolo",
},
},
{
name: "multiple values",
expr: `event.name == "test/yolo" || event.name == 'test/foobar'`,
expectedStr: "event.name == vars.a || event.name == vars.b",
expectedArgs: map[string]any{
"a": "test/yolo",
"b": "test/foobar",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
expr, vars := liftLiterals(test.expr)
assert.Equal(t, test.expectedStr, expr)
assert.Equal(t, test.expectedArgs, vars.Map())
})
}
}