about summary refs log tree commit diff stats
path: root/gomponents_test.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2022-11-03 11:24:26 +0100
committerGitHub2022-11-03 11:24:26 +0100
commit3bb4e3efeac645acc02781af59a1399f6f8e0795 (patch)
tree1782e24961e2388d39e6a00219c4d4aa8f334f9f /gomponents_test.go
parent34df17d356afbb6293fc856007f18cc62d112dcb (diff)
downloadgomponents-3bb4e3efeac645acc02781af59a1399f6f8e0795.tar.lz
gomponents-3bb4e3efeac645acc02781af59a1399f6f8e0795.tar.zst
gomponents-3bb4e3efeac645acc02781af59a1399f6f8e0795.zip
Add Rawf (#114)
Like `Raw`, but interpolates like `Textf`.
Diffstat (limited to 'gomponents_test.go')
-rw-r--r--gomponents_test.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/gomponents_test.go b/gomponents_test.go
index ffde46d..32304f3 100644
--- a/gomponents_test.go
+++ b/gomponents_test.go
@@ -212,6 +212,21 @@ func ExampleRaw() {
 	// Output: <span><button onclick="javascript:alert('Party time!')">Party hats</button> &gt; normal hats.</span>
 }
 
+func TestRawf(t *testing.T) {
+	t.Run("renders interpolated and raw text", func(t *testing.T) {
+		e := g.Rawf("<%v>", "div")
+		assert.Equal(t, "<div>", e)
+	})
+}
+
+func ExampleRawf() {
+	e := g.El("span",
+		g.Rawf(`<button onclick="javascript:alert('%v')">Party hats</button> &gt; normal hats.`, "Party time!"),
+	)
+	_ = e.Render(os.Stdout)
+	// Output: <span><button onclick="javascript:alert('Party time!')">Party hats</button> &gt; normal hats.</span>
+}
+
 func TestGroup(t *testing.T) {
 	t.Run("groups multiple nodes into one", func(t *testing.T) {
 		children := []g.Node{g.El("br", g.Attr("id", "hat")), g.El("hr")}