mirror of
https://github.com/danog/liquid.git
synced 2024-11-30 06:39:02 +01:00
1. fix
This commit is contained in:
parent
e0ae1590bf
commit
dd12222409
@ -2,6 +2,7 @@ package liquid
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
@ -42,13 +43,14 @@ func TestEngine_ParseAndRenderString_ptr_to_hash(t *testing.T) {
|
||||
params := map[string]interface{}{
|
||||
"message": &map[string]interface{}{
|
||||
"Text": "hello",
|
||||
"jsonNumber" : json.Number("123"),
|
||||
},
|
||||
}
|
||||
engine := NewEngine()
|
||||
template := "{{ message.Text }}"
|
||||
template := "{{ message.Text }} {{message.jsonNumber}}"
|
||||
str, err := engine.ParseAndRenderString(template, params)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "hello", str)
|
||||
require.Equal(t, "hello 123", str)
|
||||
}
|
||||
|
||||
type testStruct struct{ Text string }
|
||||
|
@ -1,6 +1,7 @@
|
||||
package values
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@ -44,6 +45,13 @@ func convertValueToInt(value interface{}, typ reflect.Type) (int64, error) {
|
||||
return 0, conversionError("", value, typ)
|
||||
}
|
||||
return v, nil
|
||||
case json.Number:
|
||||
v, err := strconv.ParseInt(value.String(), 10, 64)
|
||||
if err != nil {
|
||||
return 0, conversionError("", value, typ)
|
||||
}
|
||||
return v, nil
|
||||
|
||||
}
|
||||
return 0, conversionError("", value, typ)
|
||||
}
|
||||
@ -57,6 +65,12 @@ func convertValueToFloat(value interface{}, typ reflect.Type) (float64, error) {
|
||||
return 0, conversionError("", value, typ)
|
||||
}
|
||||
return v, nil
|
||||
case json.Number:
|
||||
v, err := strconv.ParseFloat(value.String(), 64)
|
||||
if err != nil {
|
||||
return 0, conversionError("", value, typ)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
return 0, conversionError("", value, typ)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user