summaryrefslogtreecommitdiffstats
path: root/hugolib/template_test.go
diff options
context:
space:
mode:
authorTatsushi Demachi <tdemachi@gmail.com>2014-10-22 00:51:29 +0900
committerspf13 <steve.francia@gmail.com>2014-11-01 23:00:46 -0400
commitaf47e5a2cfc5441005cccbb1684f3850a0f62bd1 (patch)
tree68d564ffa10e2b981f9ee4c9eaab06c920752fb9 /hugolib/template_test.go
parentd4ed59198a5e01010269ddd1f0b281bdfad8f46c (diff)
Extend template's mod and modBool functions to accept any int types
Fixes #575
Diffstat (limited to 'hugolib/template_test.go')
-rw-r--r--hugolib/template_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/hugolib/template_test.go b/hugolib/template_test.go
index b4d95f0b4..a573f1125 100644
--- a/hugolib/template_test.go
+++ b/hugolib/template_test.go
@@ -123,6 +123,81 @@ func TestDoArithmetic(t *testing.T) {
}
}
+func TestMod(t *testing.T) {
+ for i, this := range []struct {
+ a interface{}
+ b interface{}
+ expect interface{}
+ }{
+ {3, 2, int64(1)},
+ {3, 1, int64(0)},
+ {3, 0, false},
+ {0, 3, int64(0)},
+ {3.1, 2, false},
+ {3, 2.1, false},
+ {3.1, 2.1, false},
+ {int8(3), int8(2), int64(1)},
+ {int16(3), int16(2), int64(1)},
+ {int32(3), int32(2), int64(1)},
+ {int64(3), int64(2), int64(1)},
+ } {
+ result, err := Mod(this.a, this.b)
+ if b, ok := this.expect.(bool); ok && !b {
+ if err == nil {
+ t.Errorf("[%d] modulo didn't return an expected error")
+ }
+ } else {
+ if err != nil {
+ t.Errorf("[%d] failed: %s", i, err)
+ continue
+ }
+ if !reflect.DeepEqual(result, this.expect) {
+ t.Errorf("[%d] modulo got %v but expected %v", i, result, this.expect)
+ }
+ }
+ }
+}
+
+func TestModBool(t *testing.T) {
+ for i, this := range []struct {
+ a interface{}
+ b interface{}
+ expect interface{}
+ }{
+ {3, 3, true},
+ {3, 2, false},
+ {3, 1, true},
+ {3, 0, nil},
+ {0, 3, true},
+ {3.1, 2, nil},
+ {3, 2.1, nil},
+ {3.1, 2.1, nil},
+ {int8(3), int8(3), true},
+ {int8(3), int8(2), false},
+ {int16(3), int16(3), true},
+ {int16(3), int16(2), false},
+ {int32(3), int32(3), true},
+ {int32(3), int32(2), false},
+ {int64(3), int64(3), true},
+ {int64(3), int64(2), false},
+ } {
+ result, err := ModBool(this.a, this.b)
+ if this.expect == nil {
+ if err == nil {
+ t.Errorf("[%d] modulo didn't return an expected error")
+ }
+ } else {
+ if err != nil {
+ t.Errorf("[%d] failed: %s", i, err)
+ continue
+ }
+ if !reflect.DeepEqual(result, this.expect) {
+ t.Errorf("[%d] modulo got %v but expected %v", i, result, this.expect)
+ }
+ }
+ }
+}
+
func TestFirst(t *testing.T) {
for i, this := range []struct {
count interface{}