From 222559a6c6ac9df99312bb464fefd63603ec2a65 Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Thu, 20 Jul 2017 09:42:36 -0400 Subject: [PATCH] Allow value to be a pointer --- evaluator/value.go | 3 +++ evaluator/value_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/evaluator/value.go b/evaluator/value.go index d3676ca..ec77efa 100644 --- a/evaluator/value.go +++ b/evaluator/value.go @@ -36,6 +36,9 @@ func ValueOf(value interface{}) Value { return wrapperValue{value} } switch rk { + case reflect.Ptr: + rv := reflect.ValueOf(value) + return ValueOf(rv.Elem().Interface()) case reflect.String: return stringValue{wrapperValue{value}} case reflect.Array, reflect.Slice: diff --git a/evaluator/value_test.go b/evaluator/value_test.go index 41cea62..d654b74 100644 --- a/evaluator/value_test.go +++ b/evaluator/value_test.go @@ -54,4 +54,9 @@ func TestValue_hash(t *testing.T) { withSizeKey := ValueOf(map[string]interface{}{"size": "value"}) require.Equal(t, "value", withSizeKey.IndexValue(ValueOf("size")).Interface()) + + hashPtr := ValueOf(&map[string]interface{}{"key": "value"}) + require.Equal(t, "value", hashPtr.IndexValue(ValueOf("key")).Interface()) + require.Equal(t, nil, hashPtr.IndexValue(ValueOf("missing_key")).Interface()) + require.Equal(t, 1, hashPtr.PropertyValue(ValueOf("size")).Interface()) }