From f387a7123040d9414350bf783bdeff17ac0572c7 Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Thu, 22 Sep 2022 09:41:06 +0200 Subject: Add generic Map implementation (#108) Instead of waiting for a good time to switch the `Map` implementation, I've decided to just offer two implementations: one for Go versions before 1.18, and one for 1.18 and onwards. This is achieved using build tags in the source files. This is obviously a breaking change for consumers of this library that use Go 1.18 and onwards. See #88--- gomponents_test.go | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'gomponents_test.go') diff --git a/gomponents_test.go b/gomponents_test.go index d8e9e07..ffde46d 100644 --- a/gomponents_test.go +++ b/gomponents_test.go @@ -133,7 +133,7 @@ func TestEl(t *testing.T) { assert.Equal(t, `

`, e) }) - t.Run("renders outside if node does not implement placer", func(t *testing.T) { + t.Run("renders outside if node does not implement nodeTypeDescriber", func(t *testing.T) { e := g.El("div", outsider{}) assert.Equal(t, `
outsider
`, e) }) @@ -248,28 +248,6 @@ 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, ``, list) - }) -} - -func ExampleMap() { - items := []string{"party hat", "super hat"} - e := g.El("ul", g.Group(g.Map(len(items), func(i int) g.Node { - return g.El("li", g.Text(items[i])) - }))) - _ = e.Render(os.Stdout) - // Output: -} - func TestIf(t *testing.T) { t.Run("returns node if condition is true", func(t *testing.T) { n := g.El("div", g.If(true, g.El("span"))) -- cgit 1.4.1