summaryrefslogtreecommitdiffstats
path: root/transform/livereloadinject/livereloadinject_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'transform/livereloadinject/livereloadinject_test.go')
-rw-r--r--transform/livereloadinject/livereloadinject_test.go42
1 files changed, 30 insertions, 12 deletions
diff --git a/transform/livereloadinject/livereloadinject_test.go b/transform/livereloadinject/livereloadinject_test.go
index 413ca7b43..4dd256bb0 100644
--- a/transform/livereloadinject/livereloadinject_test.go
+++ b/transform/livereloadinject/livereloadinject_test.go
@@ -15,27 +15,45 @@ package livereloadinject
import (
"bytes"
- "fmt"
"strings"
"testing"
+ qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/transform"
)
func TestLiveReloadInject(t *testing.T) {
- doTestLiveReloadInject(t, "</body>")
- doTestLiveReloadInject(t, "</BODY>")
-}
+ c := qt.New(t)
-func doTestLiveReloadInject(t *testing.T, bodyEndTag string) {
- out := new(bytes.Buffer)
- in := strings.NewReader(bodyEndTag)
+ expectBase := `<script data-no-instant>document.write('<script src="/livereload.js?port=1313&mindelay=10&v=2"></' + 'script>')</script>`
+ apply := func(s string) string {
+ out := new(bytes.Buffer)
+ in := strings.NewReader(s)
- tr := transform.New(New(1313))
- tr.Apply(out, in)
+ tr := transform.New(New(1313))
+ tr.Apply(out, in)
- expected := fmt.Sprintf(`<script data-no-instant>document.write('<script src="/livereload.js?port=1313&mindelay=10&v=2"></' + 'script>')</script>%s`, bodyEndTag)
- if out.String() != expected {
- t.Errorf("Expected %s got %s", expected, out.String())
+ return out.String()
}
+
+ c.Run("Head lower", func(c *qt.C) {
+ c.Assert(apply("<html><head>foo"), qt.Equals, "<html><head>"+expectBase+"foo")
+ })
+
+ c.Run("Head upper", func(c *qt.C) {
+ c.Assert(apply("<html><HEAD>foo"), qt.Equals, "<html><HEAD>"+expectBase+"foo")
+ })
+
+ c.Run("Body lower", func(c *qt.C) {
+ c.Assert(apply("foo</body>"), qt.Equals, "foo"+expectBase+"</body>")
+ })
+
+ c.Run("Body upper", func(c *qt.C) {
+ c.Assert(apply("foo</BODY>"), qt.Equals, "foo"+expectBase+"</BODY>")
+ })
+
+ c.Run("No match", func(c *qt.C) {
+ c.Assert(apply("<h1>No match</h1>"), qt.Equals, "<h1>No match</h1>")
+ })
+
}