Update argument type of set expr function

It changes 3rd argument type os set expr function from TypedValue to interface, since GvalParser parses argument to native types before evaluating the expression.
This commit is contained in:
Vivek Patel
2022-02-03 19:30:30 +05:30
parent 8a8cf42e93
commit f42d707bfb
5 changed files with 102 additions and 12 deletions
+26 -4
View File
@@ -6,6 +6,12 @@ import (
"testing"
)
func Example_simpleExpression() {
eval(`40 + 2`, nil)
// output:
// 42
}
func TestParser(t *testing.T) {
var (
req = require.New(t)
@@ -23,8 +29,24 @@ func TestParser(t *testing.T) {
req.True(result)
}
func Example_simpleExpresion() {
eval(`40 + 2`, nil)
// output:
// 42
func TestGvalParser(t *testing.T) {
var (
req = require.New(t)
ctx = context.Background()
p = NewGvalParser()
vv, err = NewVars(map[string]interface{}{
"vars": &Vars{},
"key": "foo",
"value": Must(NewString("foo")),
})
result interface{}
)
req.NoError(err)
pp, err := p.Parse("toJSON(set(vars, key, value))")
req.NoError(err)
result, err = pp.Eval(ctx, vv)
req.NoError(err)
req.Equal("{\"foo\":{\"@value\":\"foo\",\"@type\":\"String\"}}", result)
}