Skip to content

Commit affb30e

Browse files
committed
Add extra fetch test for funcs
1 parent 50bdb0e commit affb30e

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

expr_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,24 @@ func TestExpr(t *testing.T) {
808808
}
809809
}
810810

811+
func TestExpr_eval_with_env(t *testing.T) {
812+
_, err := expr.Eval("true", expr.Env(map[string]interface{}{}))
813+
assert.Error(t, err)
814+
assert.Contains(t, err.Error(), "misused")
815+
}
816+
817+
func TestExpr_fetch_from_func(t *testing.T) {
818+
_, err := expr.Eval("foo.Value", map[string]interface{}{
819+
"foo": func() {},
820+
})
821+
assert.Error(t, err)
822+
assert.Contains(t, err.Error(), "cannot fetch Value from func()")
823+
}
824+
825+
//
826+
// Mock types
827+
//
828+
811829
type mockEnv struct {
812830
Any interface{}
813831
Int, One, Two, Three int
@@ -903,9 +921,3 @@ type segment struct {
903921
Destination string
904922
Date time.Time
905923
}
906-
907-
func TestExpr_eval_with_env(t *testing.T) {
908-
_, err := expr.Eval("true", expr.Env(map[string]interface{}{}))
909-
assert.Error(t, err)
910-
assert.Contains(t, err.Error(), "misused")
911-
}

vm/runtime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func fetch(from interface{}, i interface{}) interface{} {
4646
if value.IsValid() && value.CanInterface() {
4747
return value.Interface()
4848
}
49+
50+
case reflect.Func:
51+
panic(fmt.Sprintf("cannot fetch %v from %T", i, from))
4952
}
5053
return nil
5154
}

0 commit comments

Comments
 (0)