Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ var evalTests = []evalTest{
struct{ Foo struct{ Bar bool } }{Foo: struct{ Bar bool }{Bar: true}},
true,
},
{
`Foo.Bar`,
&struct{ Foo *struct{ Bar bool } }{Foo: &struct{ Bar bool }{Bar: true}},
true,
},
{
"foo[2]",
map[string]interface{}{"foo": []rune{'a', 'b', 'c'}},
Expand Down Expand Up @@ -162,6 +167,29 @@ var evalTests = []evalTest{
}{1, 1},
true,
},
{
`[true][A]`,
&struct{ A int }{0},
true,
},
{
`A-1`,
&struct{ A int }{1},
float64(0),
},
{
`A == 0`,
&struct{ A uint8 }{0},
true,
},
{
`A == B`,
&struct {
A uint8
B float64
}{1, 1},
true,
},
{
`5 in 0..9`,
nil,
Expand All @@ -187,6 +215,11 @@ var evalTests = []evalTest{
map[string]interface{}{"foo": map[string]interface{}{"bar": map[string]interface{}{"baz": true}}},
true,
},
{
"foo.Bar['baz']",
map[string]interface{}{"foo": &struct{ Bar map[string]interface{}}{Bar: map[string]interface{}{"baz": true}}},
true,
},
{
`60 & 13`,
nil,
Expand Down
5 changes: 5 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func extract(from interface{}, it interface{}) (interface{}, error) {
if value.IsValid() && value.CanInterface() {
return value.Interface(), nil
}
case reflect.Ptr:
derefValue := reflect.ValueOf(from).Elem()
if derefValue.IsValid() && derefValue.CanInterface() {
return extract(derefValue.Interface(), it)
}
}
}
return nil, fmt.Errorf("can't get %q from %T", it, from)
Expand Down