You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
"github.com/Knetic/govaluate"
)
func main() {
funcs := map[string]govaluate.ExpressionFunction{
"yes": func(args ...interface{}) (interface{}, error) {
fmt.Println("should execute", args)
return nil, nil
},
"no": func(args ...interface{}) (interface{}, error) {
fmt.Println("should NOT execute", args)
return nil, nil
},
}
str := ` [var] == true ? yes('good') : no ('bad')`
exp, e := govaluate.NewEvaluableExpressionWithFunctions(str, funcs)
if e != nil {
fmt.Println(e)
}
vars := map[string]interface{}{
"var": true,
}
fmt.Println("----Exec with value is true----")
exp.Evaluate(vars)
fmt.Println("----Exec with value is false----")
vars["var"] = false
exp.Evaluate(vars)
}
----Exec with value is true----
should execute [good]
should NOT execute [bad]
----Exec with value is false----
should NOT execute [bad]
Program exited.
The text was updated successfully, but these errors were encountered:
The Ternary operator bas a BUG,
in the expression
true ? say('yes) : say('no')
I get BOTH 'yes' and 'no' as an output when I should only get 'yes'
in the expression
false ? say('yes') : say('no')
I get only'no' as expected
Can someone help me with this?
Thank you,
Alex C.
please see attached code for testing
https://go.dev/play/p/NodbvidfIfa
The text was updated successfully, but these errors were encountered: