summaryrefslogtreecommitdiffstats
path: root/hugolib/template_test.go
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2014-10-10 00:57:57 +0200
committerspf13 <steve.francia@gmail.com>2014-10-15 12:39:09 -0400
commitda5d98e958a1e5bf3082b55d5d3ae41ac60f6490 (patch)
treeab420725174a0c166f4e3498bbd5bf6834a8b7e0 /hugolib/template_test.go
parentd064139cee17959f02fadce3cae97e2238abcb15 (diff)
Make First accept any int
TOML and YAML handles integers differently, creating issues when using integer values from configuration or front matter in the First template function. This currently works in YAML (parses into int), but not in TOML (parses into int64). This commit modifies First so it accepts any int. Fixes #551
Diffstat (limited to 'hugolib/template_test.go')
-rw-r--r--hugolib/template_test.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/hugolib/template_test.go b/hugolib/template_test.go
index eb0a42707..b4d95f0b4 100644
--- a/hugolib/template_test.go
+++ b/hugolib/template_test.go
@@ -125,21 +125,31 @@ func TestDoArithmetic(t *testing.T) {
func TestFirst(t *testing.T) {
for i, this := range []struct {
- count int
+ count interface{}
sequence interface{}
expect interface{}
}{
- {2, []string{"a", "b", "c"}, []string{"a", "b"}},
- {3, []string{"a", "b"}, []string{"a", "b"}},
- {2, []int{100, 200, 300}, []int{100, 200}},
+ {int(2), []string{"a", "b", "c"}, []string{"a", "b"}},
+ {int32(3), []string{"a", "b"}, []string{"a", "b"}},
+ {int64(2), []int{100, 200, 300}, []int{100, 200}},
+ {100, []int{100, 200}, []int{100, 200}},
+ {"1", []int{100, 200, 300}, []int{100}},
+ {int64(-1), []int{100, 200, 300}, false},
+ {"noint", []int{100, 200, 300}, false},
} {
results, err := First(this.count, this.sequence)
- if err != nil {
- t.Errorf("[%d] failed: %s", i, err)
- continue
- }
- if !reflect.DeepEqual(results, this.expect) {
- t.Errorf("[%d] First %d items, got %v but expected %v", i, this.count, results, this.expect)
+ if b, ok := this.expect.(bool); ok && !b {
+ if err == nil {
+ t.Errorf("[%d] First didn't return an expected error")
+ }
+ } else {
+ if err != nil {
+ t.Errorf("[%d] failed: %s", i, err)
+ continue
+ }
+ if !reflect.DeepEqual(results, this.expect) {
+ t.Errorf("[%d] First %d items, got %v but expected %v", i, this.count, results, this.expect)
+ }
}
}
}