mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-12 20:13:59 +02:00
Add Seq template func
Very similar to GNU's seq. Fixes #552 Conflicts: tpl/template.go
This commit is contained in:
@@ -133,6 +133,49 @@ func TestMd5StringEmpty(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeq(t *testing.T) {
|
||||
for i, this := range []struct {
|
||||
in []interface{}
|
||||
expect interface{}
|
||||
}{
|
||||
{[]interface{}{-2, 5}, []int{-2, -1, 0, 1, 2, 3, 4, 5}},
|
||||
{[]interface{}{1, 2, 4}, []int{1, 3}},
|
||||
{[]interface{}{1}, []int{1}},
|
||||
{[]interface{}{3}, []int{1, 2, 3}},
|
||||
{[]interface{}{3.2}, []int{1, 2, 3}},
|
||||
{[]interface{}{0}, []int{}},
|
||||
{[]interface{}{-1}, []int{-1}},
|
||||
{[]interface{}{-3}, []int{-1, -2, -3}},
|
||||
{[]interface{}{3, -2}, []int{3, 2, 1, 0, -1, -2}},
|
||||
{[]interface{}{6, -2, 2}, []int{6, 4, 2}},
|
||||
{[]interface{}{1, 0, 2}, false},
|
||||
{[]interface{}{1, -1, 2}, false},
|
||||
{[]interface{}{2, 1, 1}, false},
|
||||
{[]interface{}{2, 1, 1, 1}, false},
|
||||
{[]interface{}{2001}, false},
|
||||
{[]interface{}{}, false},
|
||||
{[]interface{}{t}, []int{}},
|
||||
{nil, false},
|
||||
} {
|
||||
|
||||
result, err := Seq(this.in...)
|
||||
|
||||
if b, ok := this.expect.(bool); ok && !b {
|
||||
if err == nil {
|
||||
t.Errorf("[%d] TestSeq didn't return an expected error %s", i)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("[%d] failed: %s", i, err)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(result, this.expect) {
|
||||
t.Errorf("[%d] TestSeq got %v but expected %v", i, result, this.expect)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoArithmetic(t *testing.T) {
|
||||
for i, this := range []struct {
|
||||
a interface{}
|
||||
|
Reference in New Issue
Block a user