From febffb600db7fbfd81827ded1b8fa3774bf42107 Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Thu, 10 Dec 2020 14:20:33 +0100 Subject: Simplify available elements (#55) `a`, `form`, `img`, `input`, `label`, `option`, `progress`, `select`, and `textarea` are now just regular elements (without helper parameters), because: - Sometimes the use case doesn't fit (`a` as anchor without href, for example) - There's no reason these are special among the others, so streamlining them makes sense Also added new attributes `action`, `alt`, `for`, `method` that I had somehow missed.--- html/elements_test.go | 64 ++++++++------------------------------------------- 1 file changed, 9 insertions(+), 55 deletions(-) (limited to 'html/elements_test.go') diff --git a/html/elements_test.go b/html/elements_test.go index f89919d..e9220e5 100644 --- a/html/elements_test.go +++ b/html/elements_test.go @@ -27,63 +27,9 @@ func TestDoctype(t *testing.T) { }) } -func TestFormEl(t *testing.T) { - t.Run("returns a form element with action and method attributes", func(t *testing.T) { - assert.Equal(t, `
`, FormEl("/", "post")) - }) -} - -func TestInput(t *testing.T) { - t.Run("returns an input element with attributes type and name", func(t *testing.T) { - assert.Equal(t, ``, Input("text", "hat")) - }) -} - -func TestLabel(t *testing.T) { - t.Run("returns a label element with attribute for", func(t *testing.T) { - assert.Equal(t, ``, Label("hat", g.Text("Hat"))) - }) -} - -func TestOption(t *testing.T) { - t.Run("returns an option element with attribute label and content", func(t *testing.T) { - assert.Equal(t, ``, Option("Hat", "hat")) - }) -} - -func TestProgress(t *testing.T) { - t.Run("returns a progress element with attributes value and max", func(t *testing.T) { - assert.Equal(t, ``, Progress(5.5, 10)) - }) -} - -func TestSelect(t *testing.T) { - t.Run("returns a select element with attribute name", func(t *testing.T) { - assert.Equal(t, ``, - Select("hat", Option("Partyhat", "partyhat"))) - }) -} - -func TestTextarea(t *testing.T) { - t.Run("returns a textarea element with attribute name", func(t *testing.T) { - assert.Equal(t, ``, Textarea("hat")) - }) -} - -func TestA(t *testing.T) { - t.Run("returns an a element with a href attribute", func(t *testing.T) { - assert.Equal(t, `hat`, A("#", g.Text("hat"))) - }) -} - -func TestImg(t *testing.T) { - t.Run("returns an img element with href and alt attributes", func(t *testing.T) { - assert.Equal(t, `hat`, Img("hat.png", "hat", g.Attr("id", "image"))) - }) -} - func TestSimpleElements(t *testing.T) { cases := map[string]func(...g.Node) g.NodeFunc{ + "a": A, "address": Address, "article": Article, "aside": Aside, @@ -104,11 +50,13 @@ func TestSimpleElements(t *testing.T) { "fieldset": FieldSet, "figure": Figure, "footer": Footer, + "form": FormEl, "head": Head, "header": Header, "hgroup": HGroup, "html": HTML, "iframe": IFrame, + "label": Label, "legend": Legend, "li": Li, "main": Main, @@ -119,11 +67,14 @@ func TestSimpleElements(t *testing.T) { "object": Object, "ol": Ol, "optgroup": OptGroup, + "option": Option, "p": P, "picture": Picture, "pre": Pre, + "progress": Progress, "script": Script, "section": Section, + "select": Select, "span": Span, "style": StyleEl, "summary": Summary, @@ -131,6 +82,7 @@ func TestSimpleElements(t *testing.T) { "table": Table, "tbody": TBody, "td": Td, + "textarea": Textarea, "tfoot": TFoot, "th": Th, "thead": THead, @@ -154,6 +106,8 @@ func TestSimpleVoidKindElements(t *testing.T) { "col": Col, "embed": Embed, "hr": Hr, + "img": Img, + "input": Input, "link": Link, "meta": Meta, "param": Param, -- cgit 1.4.1