You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
704 B
35 lines
704 B
package expression |
|
|
|
import ( |
|
"fmt" |
|
"testing" |
|
) |
|
|
|
func TestExp(t *testing.T) { |
|
result, err := Evaluate("price <= maxPrice || !isActive || hasPremium", map[string]interface{}{ |
|
"price": 1200.0, |
|
"maxPrice": 1000.0, |
|
"isActive": false, |
|
"hasPremium": true, |
|
}) |
|
if err != nil { |
|
t.Error(err) |
|
return |
|
} |
|
fmt.Println("r1:", result) |
|
|
|
vars := map[string]interface{}{ |
|
"age": 35.0, |
|
"bonus": 5000.0, |
|
"salary": 120000.0, |
|
"isActive": false, |
|
"price": 899.0, |
|
"maxPrice": 1000.0, |
|
"hasPremium": true, |
|
} |
|
result, err = Evaluate("(age + bonus) > salary / 12 && !isActive || price <= maxPrice", vars) |
|
if err != nil { |
|
panic(err) |
|
} |
|
fmt.Println("r2:", result) |
|
}
|
|
|