aboutsummaryrefslogtreecommitdiffhomepage
path: root/helpers/general_test.go
diff options
context:
space:
mode:
authorbep <[email protected]>2015-02-24 10:56:16 +0100
committerspf13 <[email protected]>2015-03-12 22:08:36 -0400
commit0be2aade99a4e7d16a48cb4372d383a3d1748d10 (patch)
tree6251c13dbc4af05d839067cae70c7511e603f5fa /helpers/general_test.go
parent358dcce7a6b4a8100964597f81cf371451f6c4d3 (diff)
downloadhugo-0be2aade99a4e7d16a48cb4372d383a3d1748d10.tar.gz
hugo-0be2aade99a4e7d16a48cb4372d383a3d1748d10.zip
Add Seq template func
Very similar to GNU's seq. Fixes #552 Conflicts: tpl/template.go
Diffstat (limited to 'helpers/general_test.go')
-rw-r--r--helpers/general_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/helpers/general_test.go b/helpers/general_test.go
index e185fe08c..9d28d214c 100644
--- a/helpers/general_test.go
+++ b/helpers/general_test.go
@@ -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{}