mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
template: add some missing test cases for First
This commit is contained in:
parent
b15d0a168f
commit
a8bfaba081
2 changed files with 8 additions and 0 deletions
|
@ -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
|
// First is exposed to templates, to iterate over the first N items in a
|
||||||
// rangeable list.
|
// rangeable list.
|
||||||
func First(limit interface{}, seq interface{}) (interface{}, error) {
|
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)
|
limitv, err := cast.ToIntE(limit)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -231,6 +231,9 @@ func TestFirst(t *testing.T) {
|
||||||
{"1", []int{100, 200, 300}, []int{100}},
|
{"1", []int{100, 200, 300}, []int{100}},
|
||||||
{int64(-1), []int{100, 200, 300}, false},
|
{int64(-1), []int{100, 200, 300}, false},
|
||||||
{"noint", []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)
|
results, err := First(this.count, this.sequence)
|
||||||
if b, ok := this.expect.(bool); ok && !b {
|
if b, ok := this.expect.(bool); ok && !b {
|
||||||
|
|
Loading…
Reference in a new issue