From a8bfaba081d6a31b6371e42e0448c9850d593d82 Mon Sep 17 00:00:00 2001 From: bep Date: Wed, 18 Mar 2015 20:47:10 +0100 Subject: template: add some missing test cases for First --- tpl/template.go | 5 +++++ tpl/template_test.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/tpl/template.go b/tpl/template.go index dedb94f8e..c61a91dc7 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -289,6 +289,11 @@ func indirect(v reflect.Value) (rv reflect.Value, isNil bool) { // First is exposed to templates, to iterate over the first N items in a // rangeable list. func First(limit interface{}, seq interface{}) (interface{}, error) { + + if limit == nil || seq == nil { + return nil, errors.New("both limit and seq must be provided") + } + limitv, err := cast.ToIntE(limit) if err != nil { diff --git a/tpl/template_test.go b/tpl/template_test.go index 1197fa9bf..0c9a1ac91 100644 --- a/tpl/template_test.go +++ b/tpl/template_test.go @@ -231,6 +231,9 @@ func TestFirst(t *testing.T) { {"1", []int{100, 200, 300}, []int{100}}, {int64(-1), []int{100, 200, 300}, false}, {"noint", []int{100, 200, 300}, false}, + {1, nil, false}, + {nil, []int{100}, false}, + {1, t, false}, } { results, err := First(this.count, this.sequence) if b, ok := this.expect.(bool); ok && !b { -- cgit v1.2.3