diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2015-01-20 16:24:43 +0300 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2015-01-20 16:24:43 +0300 |
commit | f470cf9590bb7ca6841b230ef70b83f507c68fd1 (patch) | |
tree | 2b07315fb958997499c2cdd87b0a9311dedbf8e8 /tpl | |
parent | 3f0f186b91e89f8958821d25820a7a73d29fb4be (diff) |
Add tests for Apply
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/template_test.go | 42 | ||||
-rwxr-xr-x | tpl/tpl.test | bin | 0 -> 11880208 bytes |
2 files changed, 42 insertions, 0 deletions
diff --git a/tpl/template_test.go b/tpl/template_test.go index d1a8bbdbb..a96337094 100644 --- a/tpl/template_test.go +++ b/tpl/template_test.go @@ -832,6 +832,48 @@ func TestMarkdownify(t *testing.T) { } } +func TestApply(t *testing.T) { + strings := []interface{}{"a\n", "b\n"} + noStringers := []interface{}{tstNoStringer{}, tstNoStringer{}} + + var nilErr *error = nil + + chomped, _ := Apply(strings, "chomp", ".") + assert.Equal(t, []interface{}{"a", "b"}, chomped) + + chomped, _ = Apply(strings, "chomp", "c\n") + assert.Equal(t, []interface{}{"c", "c"}, chomped) + + chomped, _ = Apply(nil, "chomp", ".") + assert.Equal(t, []interface{}{}, chomped) + + _, err := Apply(strings, "apply", ".") + if err == nil { + t.Errorf("apply with apply should fail") + } + + _, err = Apply(nilErr, "chomp", ".") + if err == nil { + t.Errorf("apply with nil in seq should fail") + } + + _, err = Apply(strings, "dobedobedo", ".") + if err == nil { + t.Errorf("apply with unknown func should fail") + } + + _, err = Apply(noStringers, "chomp", ".") + if err == nil { + t.Errorf("apply when func fails should fail") + } + + _, err = Apply(tstNoStringer{}, "chomp", ".") + if err == nil { + t.Errorf("apply with non-sequence should fail") + } + +} + func TestChomp(t *testing.T) { base := "\n This is\na story " for i, item := range []string{ diff --git a/tpl/tpl.test b/tpl/tpl.test Binary files differnew file mode 100755 index 000000000..33d130bc4 --- /dev/null +++ b/tpl/tpl.test |