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

index 12c7ed28a3427ed29d35a48286d845a21d6ec26f..8a07474350dd2db3d27688993b2ae60538843278 100644 (file)
@@ -853,6 +853,21 @@ func TestChomp(t *testing.T) {
        }
 }
 
+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)