about summary refs log tree commit diff stats
path: root/gomponents_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'gomponents_test.go')
-rw-r--r--gomponents_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/gomponents_test.go b/gomponents_test.go
index 0d1c478..39b5fe6 100644
--- a/gomponents_test.go
+++ b/gomponents_test.go
@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"io"
 	"os"
+	"slices"
 	"strings"
 	"testing"
 
@@ -302,6 +303,23 @@ func ExampleMapMap() {
 	// Output: <ul><li>party: hat</li><li>super: hat</li></ul>
 }
 
+func TestMapIter(t *testing.T) {
+	items := slices.Values([]string{"party hat", "super hat"})
+	e := g.El("ul", g.MapIter(items, func(value string) g.Node {
+		return g.El("li", g.Text(value))
+	}))
+	assert.Equal(t, `<ul><li>party hat</li><li>super hat</li></ul>`, e)
+}
+
+func ExampleMapIter() {
+	items := slices.Values([]string{"party hat", "super hat"})
+	e := g.El("ul", g.MapIter(items, func(value string) g.Node {
+		return g.El("li", g.Text(value))
+	}))
+	_ = e.Render(os.Stdout)
+	// Output: <ul><li>party hat</li><li>super hat</li></ul>
+}
+
 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")}