shithub: hugo

Download patch

ref: c33eb9354886b0ba89f3689f65d2e59da18c149d
parent: 174f97a9dd6c08bad0d5074265b0dc1c86ca835f
author: Bjørn Erik Pedersen <[email protected]>
date: Wed Nov 23 05:37:09 EST 2016

tpl: Add some missing test cases

--- a/tpl/template_funcs_test.go
+++ b/tpl/template_funcs_test.go
@@ -694,6 +694,10 @@
 		t.Error("Expected error from imageConfig when passed non-existent file")
 	}
 
+	if _, err := imageConfig(""); err == nil {
+		t.Error("Expected error from imageConfig when passed empty path")
+	}
+
 	// test cache clearing
 	ResetCaches()
 
@@ -1897,6 +1901,9 @@
 		}
 	}
 
+	if _, err := markdownify(t); err == nil {
+		t.Fatalf("markdownify should have errored")
+	}
 }
 
 func TestApply(t *testing.T) {
@@ -2058,14 +2065,17 @@
 
 func TestReplaceRE(t *testing.T) {
 	for i, val := range []struct {
-		pattern string
-		repl    string
-		src     string
+		pattern interface{}
+		repl    interface{}
+		src     interface{}
 		expect  string
 		ok      bool
 	}{
 		{"^https?://([^/]+).*", "$1", "http://gohugo.io/docs", "gohugo.io", true},
 		{"^https?://([^/]+).*", "$2", "http://gohugo.io/docs", "", true},
+		{tstNoStringer{}, "$2", "http://gohugo.io/docs", "", false},
+		{"^https?://([^/]+).*", tstNoStringer{}, "http://gohugo.io/docs", "", false},
+		{"^https?://([^/]+).*", "$2", tstNoStringer{}, "", false},
 		{"(ab)", "AB", "aabbaab", "aABbaAB", true},
 		{"(ab", "AB", "aabb", "", false}, // invalid re
 	} {
@@ -2080,7 +2090,7 @@
 func TestFindRE(t *testing.T) {
 	for i, this := range []struct {
 		expr    string
-		content string
+		content interface{}
 		limit   int
 		expect  []string
 		ok      bool
@@ -2090,8 +2100,19 @@
 		{"[G|g]o", "Hugo is a static site generator written in Go.", 1, []string{"go"}, true},
 		{"[G|g]o", "Hugo is a static site generator written in Go.", 0, []string(nil), true},
 		{"[G|go", "Hugo is a static site generator written in Go.", 0, []string(nil), false},
+		{"[G|g]o", t, 0, []string(nil), false},
 	} {
-		res, err := findRE(this.expr, this.content, this.limit)
+		var (
+			res []string
+			err error
+		)
+
+		if this.limit >= 0 {
+			res, err = findRE(this.expr, this.content, this.limit)
+
+		} else {
+			res, err = findRE(this.expr, this.content)
+		}
 
 		if err != nil && this.ok {
 			t.Errorf("[%d] returned an unexpected error: %s", i, err)