shithub: hugo

Download patch

ref: a6bf6f52cefc2c81b8a97931d2d49b43e517348f
parent: 42b33102cf619e08c6b6a49a50a0995e8f14773f
author: bep <[email protected]>
date: Tue Jan 20 07:07:49 EST 2015

Add tests for Chomp

--- a/tpl/template_test.go
+++ b/tpl/template_test.go
@@ -9,6 +9,9 @@
 	"testing"
 )
 
+type tstNoStringer struct {
+}
+
 func TestGt(t *testing.T) {
 	for i, this := range []struct {
 		left          interface{}
@@ -825,6 +828,27 @@
 
 	if result != expect {
 		t.Errorf("Markdownify: got '%s', expected '%s'", result, expect)
+	}
+}
+
+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")
+		}
 	}
 }