diff options
author | Markus Wüstenberg | 2020-11-02 10:59:16 +0100 |
---|---|---|
committer | GitHub | 2020-11-02 10:59:16 +0100 |
commit | 267d40bbea6036f913c4047a6a2055b3e5d7bb96 (patch) | |
tree | ef2bcb5be63bb6f9fdfd6a608698473ac2192ea6 /gomponents_test.go | |
parent | 6c8f0c235287edf7252fe239d4c9beb258c6ff01 (diff) | |
download | gomponents-267d40bbea6036f913c4047a6a2055b3e5d7bb96.tar.lz gomponents-267d40bbea6036f913c4047a6a2055b3e5d7bb96.tar.zst gomponents-267d40bbea6036f913c4047a6a2055b3e5d7bb96.zip |
Add Map function (#40)
`Map` makes it easier to build lists of elements without having to iterate.
Diffstat (limited to 'gomponents_test.go')
-rw-r--r-- | gomponents_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gomponents_test.go b/gomponents_test.go index 3028723..0c5dc68 100644 --- a/gomponents_test.go +++ b/gomponents_test.go @@ -183,3 +183,16 @@ func TestGroup(t *testing.T) { } }) } + +func TestMap(t *testing.T) { + t.Run("maps slices to nodes", func(t *testing.T) { + items := []string{"hat", "partyhat", "turtlehat"} + lis := g.Map(len(items), func(i int) g.Node { + return g.El("li", g.Text(items[i])) + }) + + list := g.El("ul", lis...) + + assert.Equal(t, `<ul><li>hat</li><li>partyhat</li><li>turtlehat</li></ul>`, list) + }) +} |