diff --git a/tpl/template_test.go b/tpl/template_test.go index b0d18f8f4..3ea57b592 100644 --- a/tpl/template_test.go +++ b/tpl/template_test.go @@ -107,6 +107,42 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b inte } } +func TestArethmic(t *testing.T) { + for i, this := range []struct { + a interface{} + b interface{} + op rune + expect interface{} + }{ + {1, 2, '+', int64(3)}, + {1, 2, '-', int64(-1)}, + {2, 2, '*', int64(4)}, + {4, 2, '/', int64(2)}, + {uint8(1), uint8(3), '+', uint64(4)}, + {uint8(3), uint8(2), '-', uint64(1)}, + {uint8(2), uint8(2), '*', uint64(4)}, + {uint16(4), uint8(2), '/', uint64(2)}, + {4, 2, 'ยค', false}, + } { + // TODO(bep): Take precision into account. + result, err := doArithmetic(this.a, this.b, this.op) + + if b, ok := this.expect.(bool); ok && !b { + if err == nil { + t.Errorf("[%d] doArethmic didn't return an expected error", i) + } + } else { + if err != nil { + t.Errorf("[%d] failed: %s", i, err) + continue + } + if !reflect.DeepEqual(result, this.expect) { + t.Errorf("[%d] doArethmic got %v (%T) but expected %v (%T)", i, result, result, this.expect, this.expect) + } + } + } +} + func TestMod(t *testing.T) { for i, this := range []struct { a interface{}