about summary refs log tree commit diff stats
path: root/assert/assert.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-11-02 10:03:05 +0100
committerGitHub2020-11-02 10:03:05 +0100
commit6c8f0c235287edf7252fe239d4c9beb258c6ff01 (patch)
treeae1245a8e1491f5f369e8d9ef2517148d9774130 /assert/assert.go
parent92ba5904c1645e6572f5ff1b9d0e0ec629e1afb9 (diff)
downloadgomponents-6c8f0c235287edf7252fe239d4c9beb258c6ff01.tar.lz
gomponents-6c8f0c235287edf7252fe239d4c9beb258c6ff01.tar.zst
gomponents-6c8f0c235287edf7252fe239d4c9beb258c6ff01.zip
Render to Writer instead of string (#39)
The Render function has been changed to take a `Writer` instead of returning a string. This makes it possible to generate documents without having the whole content in memory.

This also removes the `gomponents.Write` function, which is now redundant.

Furthermore, the `el.Document` function has been changed to only take one child, as multiple children never make sense for it. (It's not even a child, more a sibling.)
Diffstat (limited to 'assert/assert.go')
-rw-r--r--assert/assert.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/assert/assert.go b/assert/assert.go
index b2b6002..b18ff65 100644
--- a/assert/assert.go
+++ b/assert/assert.go
@@ -1,6 +1,7 @@
 package assert
 
 import (
+	"strings"
 	"testing"
 
 	g "github.com/maragudk/gomponents"
@@ -8,8 +9,17 @@ import (
 
 // Equal checks for equality between the given expected string and the rendered Node string.
 func Equal(t *testing.T, expected string, actual g.Node) {
-	if expected != actual.Render() {
+	var b strings.Builder
+	_ = actual.Render(&b)
+	if expected != b.String() {
 		t.Errorf("expected `%v` but got `%v`", expected, actual)
 		t.FailNow()
 	}
 }
+
+// Error checks for a non-nil error.
+func Error(t *testing.T, err error) {
+	if err == nil {
+		t.FailNow()
+	}
+}