summaryrefslogtreecommitdiffstats
path: root/helpers/general_test.go
diff options
context:
space:
mode:
authorCameron Moore <moorereason@gmail.com>2017-03-13 17:55:02 -0500
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-04-30 10:56:38 +0200
commitde7c32a1a880820252e922e0c9fcf69e109c0d1b (patch)
tree07d813f2617dd4a889aaebb885a9c1281a229960 /helpers/general_test.go
parent154e18ddb9ad205055d5bd4827c87f3f0daf499f (diff)
tpl: Add template function namespaces
This commit moves almost all of the template functions into separate packages under tpl/ and adds a namespace framework. All changes should be backward compatible for end users, as all existing function names in the template funcMap are left intact. Seq and DoArithmatic have been moved out of the helpers package and into template namespaces. Most of the tests involved have been refactored, and many new tests have been written. There's still work to do, but this is a big improvement. I got a little overzealous and added some new functions along the way: - strings.Contains - strings.ContainsAny - strings.HasSuffix - strings.TrimPrefix - strings.TrimSuffix Documentation is forthcoming. Fixes #3042
Diffstat (limited to 'helpers/general_test.go')
-rw-r--r--helpers/general_test.go131
1 files changed, 0 insertions, 131 deletions
diff --git a/helpers/general_test.go b/helpers/general_test.go
index 3fa587e78..ee4ed2370 100644
--- a/helpers/general_test.go
+++ b/helpers/general_test.go
@@ -162,137 +162,6 @@ func TestFindAvailablePort(t *testing.T) {
assert.True(t, addr.Port > 0)
}
-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},
- // TODO(bep) {[]interface{}{t}, false},
- {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", 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{}
- b interface{}
- op rune
- expect interface{}
- }{
- {3, 2, '+', int64(5)},
- {3, 2, '-', int64(1)},
- {3, 2, '*', int64(6)},
- {3, 2, '/', int64(1)},
- {3.0, 2, '+', float64(5)},
- {3.0, 2, '-', float64(1)},
- {3.0, 2, '*', float64(6)},
- {3.0, 2, '/', float64(1.5)},
- {3, 2.0, '+', float64(5)},
- {3, 2.0, '-', float64(1)},
- {3, 2.0, '*', float64(6)},
- {3, 2.0, '/', float64(1.5)},
- {3.0, 2.0, '+', float64(5)},
- {3.0, 2.0, '-', float64(1)},
- {3.0, 2.0, '*', float64(6)},
- {3.0, 2.0, '/', float64(1.5)},
- {uint(3), uint(2), '+', uint64(5)},
- {uint(3), uint(2), '-', uint64(1)},
- {uint(3), uint(2), '*', uint64(6)},
- {uint(3), uint(2), '/', uint64(1)},
- {uint(3), 2, '+', uint64(5)},
- {uint(3), 2, '-', uint64(1)},
- {uint(3), 2, '*', uint64(6)},
- {uint(3), 2, '/', uint64(1)},
- {3, uint(2), '+', uint64(5)},
- {3, uint(2), '-', uint64(1)},
- {3, uint(2), '*', uint64(6)},
- {3, uint(2), '/', uint64(1)},
- {uint(3), -2, '+', int64(1)},
- {uint(3), -2, '-', int64(5)},
- {uint(3), -2, '*', int64(-6)},
- {uint(3), -2, '/', int64(-1)},
- {-3, uint(2), '+', int64(-1)},
- {-3, uint(2), '-', int64(-5)},
- {-3, uint(2), '*', int64(-6)},
- {-3, uint(2), '/', int64(-1)},
- {uint(3), 2.0, '+', float64(5)},
- {uint(3), 2.0, '-', float64(1)},
- {uint(3), 2.0, '*', float64(6)},
- {uint(3), 2.0, '/', float64(1.5)},
- {3.0, uint(2), '+', float64(5)},
- {3.0, uint(2), '-', float64(1)},
- {3.0, uint(2), '*', float64(6)},
- {3.0, uint(2), '/', float64(1.5)},
- {0, 0, '+', 0},
- {0, 0, '-', 0},
- {0, 0, '*', 0},
- {"foo", "bar", '+', "foobar"},
- {3, 0, '/', false},
- {3.0, 0, '/', false},
- {3, 0.0, '/', false},
- {uint(3), uint(0), '/', false},
- {3, uint(0), '/', false},
- {-3, uint(0), '/', false},
- {uint(3), 0, '/', false},
- {3.0, uint(0), '/', false},
- {uint(3), 0.0, '/', false},
- {3, "foo", '+', false},
- {3.0, "foo", '+', false},
- {uint(3), "foo", '+', false},
- {"foo", 3, '+', false},
- {"foo", "bar", '-', false},
- {3, 2, '%', false},
- } {
- result, err := DoArithmetic(this.a, this.b, this.op)
- if b, ok := this.expect.(bool); ok && !b {
- if err == nil {
- t.Errorf("[%d] doArithmetic 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] doArithmetic got %v but expected %v", i, result, this.expect)
- }
- }
- }
-}
-
func TestToLowerMap(t *testing.T) {
tests := []struct {