1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-26 23:14:39 +01:00

Add some tests

This commit is contained in:
Oliver Steele 2017-07-21 11:56:04 -04:00
parent df3f7b2c7d
commit a07e5fa28b
4 changed files with 23 additions and 11 deletions

View File

@ -1,16 +1,12 @@
// Package evaluator defines methods such as sorting, comparison, and type conversion, that apply to interface types.
//
// It is similar to, and makes heavy use of, the reflect package.
//
// Since the intent is to provide runtime services for the Liquid expression interpreter,
// this package does not implement "generic" generics.
// It attempts to implement Liquid semantics (which are largely Ruby semantics).
package evaluator
import (
"reflect"
)
// TODO Length is now only used by the "size" filter.
// Maybe it should go somewhere else.
// Length returns the length of a string or array. In keeping with Liquid semantics,
// and contra Go, it does not return the size of a map.
func Length(value interface{}) int {

9
evaluator/docs.go Normal file
View File

@ -0,0 +1,9 @@
package evaluator
// Package evaluator defines methods such as sorting, comparison, and type conversion, that apply to interface types.
//
// It is similar to, and makes heavy use of, the reflect package.
//
// Since the intent is to provide runtime services for the Liquid expression interpreter,
// this package does not implement "generic" generics.
// It attempts to implement Liquid semantics (which are largely Ruby semantics).

View File

@ -10,11 +10,12 @@ import (
func TestValue(t *testing.T) {
var (
nv = ValueOf(nil)
// fv = ValueOf(false)
// tv = ValueOf(true)
iv = ValueOf(123)
// fv = ValueOf(123.0)
)
require.Equal(t, nil, nv.Interface())
require.Equal(t, true, ValueOf(true).Interface())
require.Equal(t, false, ValueOf(false).Interface())
require.Equal(t, 123, iv.Interface())
require.Equal(t, 123, iv.Int())
require.Panics(t, func() { nv.Int() })
require.True(t, iv.Equal(ValueOf(123)))

View File

@ -15,10 +15,15 @@ var filterTests = []struct {
expected interface{}
}{
// value filters
{`4.99 | default: 2.99`, 4.99},
{`undefined | default: 2.99`, 2.99},
{`nil | default: 2.99`, 2.99},
{`false | default: 2.99`, 2.99},
{`"" | default: 2.99`, 2.99},
{`empty_list | default: 2.99`, 2.99},
{`empty_hash | default: 2.99`, 2.99},
{`true | default: 2.99`, true},
{`"true" | default: 2.99`, "true"},
{`4.99 | default: 2.99`, 4.99},
// array filters
// TODO sort_natural, uniq
@ -169,6 +174,7 @@ var filterTestBindings = map[string]interface{}{
"published_at": timeMustParse("2015-07-17T15:04:05Z"),
},
"empty_list": []interface{}{},
"empty_hash": map[string]interface{}{},
"fruits": []string{"apples", "oranges", "peaches", "plums"},
"mixed_case_list": []string{"c", "a", "B"},
"mixed_case_objects": []map[string]interface{}{