Add tests for Chomp
authorbep <bjorn.erik.pedersen@gmail.com>
Tue, 20 Jan 2015 11:07:49 +0000 (12:07 +0100)
committerbep <bjorn.erik.pedersen@gmail.com>
Tue, 20 Jan 2015 11:07:49 +0000 (12:07 +0100)
tpl/template_test.go

index 159d6cf536013f6ebd18edf5a1609d231db793c9..9a726f3fa546bc4b1533d38735af7af0032c8c9f 100644 (file)
@@ -9,6 +9,9 @@ import (
        "testing"
 )
 
+type tstNoStringer struct {
+}
+
 func TestGt(t *testing.T) {
        for i, this := range []struct {
                left          interface{}
@@ -828,6 +831,27 @@ func TestMarkdownify(t *testing.T) {
        }
 }
 
+func TestChomp(t *testing.T) {
+       base := "\n This is\na story "
+       for i, item := range []string{
+               "\n",
+               "\r",
+               "\r\n",
+       } {
+               chomped, _ := Chomp(base + item)
+
+               if chomped != base {
+                       t.Errorf("[%d] Chomp failed, got '%v'", i, chomped)
+               }
+
+               _, err := Chomp(tstNoStringer{})
+
+               if err == nil {
+                       t.Errorf("Chomp should fail")
+               }
+       }
+}
+
 func TestSafeHtml(t *testing.T) {
        for i, this := range []struct {
                str                 string