shithub: hugo

Download patch

ref: 99aee30410f6908ac9c11a463eb45d1f28f5ca94
parent: 26856c3b7555d3b1973de2349af7d680d755e58a
author: bep <[email protected]>
date: Tue Jan 20 07:30:49 EST 2015

Add tests for Replace

--- a/tpl/template_test.go
+++ b/tpl/template_test.go
@@ -853,6 +853,21 @@
 	}
 }
 
+func TestReplace(t *testing.T) {
+	v, _ := Replace("aab", "a", "b")
+	assert.Equal(t, "bbb", v)
+	v, _ = Replace("11a11", 1, 2)
+	assert.Equal(t, "22a22", v)
+	v, _ = Replace(12345, 1, 2)
+	assert.Equal(t, "22345", v)
+	_, e := Replace(tstNoStringer{}, "a", "b")
+	assert.NotNil(t, e, "tstNoStringer isn't trimmable")
+	_, e = Replace("a", tstNoStringer{}, "b")
+	assert.NotNil(t, e, "tstNoStringer cannot be converted to string")
+	_, e = Replace("a", "b", tstNoStringer{})
+	assert.NotNil(t, e, "tstNoStringer cannot be converted to string")
+}
+
 func TestTrim(t *testing.T) {
 	v, _ := Trim("1234 my way 13", "123")
 	assert.Equal(t, "4 my way ", v)