1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 06:08:57 +01:00

Allow value to be a pointer

This commit is contained in:
Oliver Steele 2017-07-20 09:42:36 -04:00
parent 17def2556e
commit 222559a6c6
2 changed files with 8 additions and 0 deletions

View File

@ -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:

View File

@ -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())
}