From a07e5fa28b2c04c10594fc57c5bcc7d86a02649d Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Fri, 21 Jul 2017 11:56:04 -0400 Subject: [PATCH] Add some tests --- evaluator/arrays.go | 10 +++------- evaluator/docs.go | 9 +++++++++ evaluator/value_test.go | 7 ++++--- filters/standard_filters_test.go | 8 +++++++- 4 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 evaluator/docs.go diff --git a/evaluator/arrays.go b/evaluator/arrays.go index e7e4f98..72b42ea 100644 --- a/evaluator/arrays.go +++ b/evaluator/arrays.go @@ -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 { diff --git a/evaluator/docs.go b/evaluator/docs.go new file mode 100644 index 0000000..82802f6 --- /dev/null +++ b/evaluator/docs.go @@ -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). diff --git a/evaluator/value_test.go b/evaluator/value_test.go index 82ea85f..cd56ce0 100644 --- a/evaluator/value_test.go +++ b/evaluator/value_test.go @@ -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))) diff --git a/filters/standard_filters_test.go b/filters/standard_filters_test.go index b2afc53..c378641 100644 --- a/filters/standard_filters_test.go +++ b/filters/standard_filters_test.go @@ -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{}{