From dd1db334ac15f3bdb67b40973668d1d7b9ca7f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 6 Feb 2016 18:28:26 +0100 Subject: [PATCH] transform: Add missing test case in livereloadinject * Test for both and * This also cosmetically changes the behaviour, as the case of the end body tag is kept. --- transform/livereloadinject.go | 11 ++++++++--- transform/livereloadinject_test.go | 10 ++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/transform/livereloadinject.go b/transform/livereloadinject.go index 789ff9d22..9eab45f78 100644 --- a/transform/livereloadinject.go +++ b/transform/livereloadinject.go @@ -15,15 +15,20 @@ package transform import ( "bytes" + "fmt" ) func LiveReloadInject(ct contentTransformer) { - match := []byte("") - replace := []byte(``) + endBodyTag := "" + match := []byte(endBodyTag) + replaceTemplate := `%s` + replace := []byte(fmt.Sprintf(replaceTemplate, endBodyTag)) newcontent := bytes.Replace(ct.Content(), match, replace, -1) if len(newcontent) == len(ct.Content()) { - match := []byte("") + endBodyTag = "" + replace := []byte(fmt.Sprintf(replaceTemplate, endBodyTag)) + match := []byte(endBodyTag) newcontent = bytes.Replace(ct.Content(), match, replace, -1) } diff --git a/transform/livereloadinject_test.go b/transform/livereloadinject_test.go index 0c47cb109..5aea8689c 100644 --- a/transform/livereloadinject_test.go +++ b/transform/livereloadinject_test.go @@ -15,18 +15,24 @@ package transform import ( "bytes" + "fmt" "github.com/spf13/hugo/helpers" "testing" ) func TestLiveReloadInject(t *testing.T) { + doTestLiveReloadInject(t, "") + doTestLiveReloadInject(t, "") +} + +func doTestLiveReloadInject(t *testing.T, bodyEndTag string) { out := new(bytes.Buffer) - in := helpers.StringToReader("") + in := helpers.StringToReader(bodyEndTag) tr := NewChain(LiveReloadInject) tr.Apply(out, in, []byte("path")) - expected := `` + expected := fmt.Sprintf(`%s`, bodyEndTag) if string(out.Bytes()) != expected { t.Errorf("Expected %s got %s", expected, string(out.Bytes())) }