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:
parent
17def2556e
commit
222559a6c6
@ -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:
|
||||
|
@ -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())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user