File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -828,15 +828,20 @@ func TestExpr_fetch_from_func(t *testing.T) {
828
828
assert .Contains (t , err .Error (), "cannot fetch Value from func()" )
829
829
}
830
830
831
- func TestExpr_reference_options (t * testing.T ) {
832
- options := []expr.Option {expr .Env (map [string ]interface {}{})}
831
+ func TestExpr_map_default_values (t * testing.T ) {
832
+ env := map [string ]interface {}{
833
+ "foo" : map [string ]string {},
834
+ "bar" : map [string ]* string {},
835
+ }
833
836
834
- e , err := expr .Compile ("'hello world'" , options ... )
835
- assert .NoError (t , err )
837
+ input := `foo['missing'] == '' && bar['missing'] == nil`
838
+
839
+ program , err := expr .Compile (input , expr .Env (env ))
840
+ require .NoError (t , err )
836
841
837
- output , err := expr .Run (e , "'hello world'" )
838
- assert .NoError (t , err )
839
- assert .Equal (t , "hello world" , output )
842
+ output , err := expr .Run (program , env )
843
+ require .NoError (t , err )
844
+ require .Equal (t , true , output )
840
845
}
841
846
842
847
//
Original file line number Diff line number Diff line change @@ -36,8 +36,13 @@ func fetch(from interface{}, i interface{}) interface{} {
36
36
37
37
case reflect .Map :
38
38
value := v .MapIndex (reflect .ValueOf (i ))
39
- if value .IsValid () && value .CanInterface () {
40
- return value .Interface ()
39
+ if value .IsValid () {
40
+ if value .CanInterface () {
41
+ return value .Interface ()
42
+ }
43
+ } else {
44
+ elem := reflect .TypeOf (from ).Elem ()
45
+ return reflect .Zero (elem ).Interface ()
41
46
}
42
47
43
48
case reflect .Struct :
You can’t perform that action at this time.
0 commit comments