about summary refs log tree commit diff stats
path: root/html/elements_test.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2024-06-06 11:56:27 +0200
committerMarkus Wüstenberg2024-06-06 11:56:27 +0200
commitd55a223e8af294678f10126bff9057ec38d7d978 (patch)
tree7e5e5770b4d2d6490c14809eedda325ee9efef7f /html/elements_test.go
parentd944acd39fd6c987ea3cdd57c2cec525e918425e (diff)
downloadgomponents-d55a223e8af294678f10126bff9057ec38d7d978.tar.lz
gomponents-d55a223e8af294678f10126bff9057ec38d7d978.tar.zst
gomponents-d55a223e8af294678f10126bff9057ec38d7d978.zip
Deprecate DataAttr, StyleAttr, TitleAttr, FormEl
This change addresses #170 by deprecating some HTML helpers in favor of using one of the styles as a main one,
selected based on what I think is the main use case.

- For `Data`, it's the attribute. I don't see much use of the `<data>` element in the wild.
- For `Style`, it's the attribute. The `style` attribute is everywhere, the `<style>` element is perhaps less so (but not much). This was the hardest one to decide.
- For `Title`, it's the attribute. The `<title>` element only shows up once per document.
- For `Form`, it's the element. I haven't seen much use of the `data` attribute in the wild.

I know this is arguably not a "consistent" approach, but I think it makes for a much nicer API, simply because the most-used option will not be a suffixed version.
Diffstat (limited to 'html/elements_test.go')
-rw-r--r--html/elements_test.go233
1 files changed, 120 insertions, 113 deletions
diff --git a/html/elements_test.go b/html/elements_test.go
index cced400..ffb225a 100644
--- a/html/elements_test.go
+++ b/html/elements_test.go
@@ -28,128 +28,135 @@ func TestDoctype(t *testing.T) {
 }
 
 func TestSimpleElements(t *testing.T) {
-	cases := map[string]func(...g.Node) g.Node{
-		"a":          A,
-		"abbr":       Abbr,
-		"address":    Address,
-		"article":    Article,
-		"aside":      Aside,
-		"audio":      Audio,
-		"b":          B,
-		"blockquote": BlockQuote,
-		"body":       Body,
-		"button":     Button,
-		"canvas":     Canvas,
-		"caption":    Caption,
-		"cite":       Cite,
-		"code":       Code,
-		"colgroup":   ColGroup,
-		"data":       DataEl,
-		"datalist":   DataList,
-		"dd":         Dd,
-		"del":        Del,
-		"details":    Details,
-		"dfn":        Dfn,
-		"dialog":     Dialog,
-		"div":        Div,
-		"dl":         Dl,
-		"dt":         Dt,
-		"em":         Em,
-		"fieldset":   FieldSet,
-		"figcaption": FigCaption,
-		"figure":     Figure,
-		"footer":     Footer,
-		"form":       FormEl,
-		"h1":         H1,
-		"h2":         H2,
-		"h3":         H3,
-		"h4":         H4,
-		"h5":         H5,
-		"h6":         H6,
-		"head":       Head,
-		"header":     Header,
-		"hgroup":     HGroup,
-		"html":       HTML,
-		"i":          I,
-		"iframe":     IFrame,
-		"ins":        Ins,
-		"kbd":        Kbd,
-		"label":      Label,
-		"legend":     Legend,
-		"li":         Li,
-		"main":       Main,
-		"mark":       Mark,
-		"menu":       Menu,
-		"meter":      Meter,
-		"nav":        Nav,
-		"noscript":   NoScript,
-		"object":     Object,
-		"ol":         Ol,
-		"optgroup":   OptGroup,
-		"option":     Option,
-		"p":          P,
-		"picture":    Picture,
-		"pre":        Pre,
-		"progress":   Progress,
-		"q":          Q,
-		"s":          S,
-		"samp":       Samp,
-		"script":     Script,
-		"section":    Section,
-		"select":     Select,
-		"small":      Small,
-		"span":       Span,
-		"strong":     Strong,
-		"style":      StyleEl,
-		"sub":        Sub,
-		"summary":    Summary,
-		"sup":        Sup,
-		"svg":        SVG,
-		"table":      Table,
-		"tbody":      TBody,
-		"td":         Td,
-		"textarea":   Textarea,
-		"tfoot":      TFoot,
-		"th":         Th,
-		"thead":      THead,
-		"time":       Time,
-		"title":      TitleEl,
-		"tr":         Tr,
-		"u":          U,
-		"ul":         Ul,
-		"var":        Var,
-		"video":      Video,
+	tests := []struct {
+		Name string
+		Func func(...g.Node) g.Node
+	}{
+		{Name: "a", Func: A},
+		{Name: "abbr", Func: Abbr},
+		{Name: "address", Func: Address},
+		{Name: "article", Func: Article},
+		{Name: "aside", Func: Aside},
+		{Name: "audio", Func: Audio},
+		{Name: "b", Func: B},
+		{Name: "blockquote", Func: BlockQuote},
+		{Name: "body", Func: Body},
+		{Name: "button", Func: Button},
+		{Name: "canvas", Func: Canvas},
+		{Name: "caption", Func: Caption},
+		{Name: "cite", Func: Cite},
+		{Name: "code", Func: Code},
+		{Name: "colgroup", Func: ColGroup},
+		{Name: "data", Func: DataEl},
+		{Name: "datalist", Func: DataList},
+		{Name: "dd", Func: Dd},
+		{Name: "del", Func: Del},
+		{Name: "details", Func: Details},
+		{Name: "dfn", Func: Dfn},
+		{Name: "dialog", Func: Dialog},
+		{Name: "div", Func: Div},
+		{Name: "dl", Func: Dl},
+		{Name: "dt", Func: Dt},
+		{Name: "em", Func: Em},
+		{Name: "fieldset", Func: FieldSet},
+		{Name: "figcaption", Func: FigCaption},
+		{Name: "figure", Func: Figure},
+		{Name: "footer", Func: Footer},
+		{Name: "form", Func: Form},
+		{Name: "form", Func: FormEl},
+		{Name: "h1", Func: H1},
+		{Name: "h2", Func: H2},
+		{Name: "h3", Func: H3},
+		{Name: "h4", Func: H4},
+		{Name: "h5", Func: H5},
+		{Name: "h6", Func: H6},
+		{Name: "head", Func: Head},
+		{Name: "header", Func: Header},
+		{Name: "hgroup", Func: HGroup},
+		{Name: "html", Func: HTML},
+		{Name: "i", Func: I},
+		{Name: "iframe", Func: IFrame},
+		{Name: "ins", Func: Ins},
+		{Name: "kbd", Func: Kbd},
+		{Name: "label", Func: Label},
+		{Name: "legend", Func: Legend},
+		{Name: "li", Func: Li},
+		{Name: "main", Func: Main},
+		{Name: "mark", Func: Mark},
+		{Name: "menu", Func: Menu},
+		{Name: "meter", Func: Meter},
+		{Name: "nav", Func: Nav},
+		{Name: "noscript", Func: NoScript},
+		{Name: "object", Func: Object},
+		{Name: "ol", Func: Ol},
+		{Name: "optgroup", Func: OptGroup},
+		{Name: "option", Func: Option},
+		{Name: "p", Func: P},
+		{Name: "picture", Func: Picture},
+		{Name: "pre", Func: Pre},
+		{Name: "progress", Func: Progress},
+		{Name: "q", Func: Q},
+		{Name: "s", Func: S},
+		{Name: "samp", Func: Samp},
+		{Name: "script", Func: Script},
+		{Name: "section", Func: Section},
+		{Name: "select", Func: Select},
+		{Name: "small", Func: Small},
+		{Name: "span", Func: Span},
+		{Name: "strong", Func: Strong},
+		{Name: "style", Func: StyleEl},
+		{Name: "sub", Func: Sub},
+		{Name: "summary", Func: Summary},
+		{Name: "sup", Func: Sup},
+		{Name: "svg", Func: SVG},
+		{Name: "table", Func: Table},
+		{Name: "tbody", Func: TBody},
+		{Name: "td", Func: Td},
+		{Name: "textarea", Func: Textarea},
+		{Name: "tfoot", Func: TFoot},
+		{Name: "th", Func: Th},
+		{Name: "thead", Func: THead},
+		{Name: "time", Func: Time},
+		{Name: "title", Func: TitleEl},
+		{Name: "tr", Func: Tr},
+		{Name: "u", Func: U},
+		{Name: "ul", Func: Ul},
+		{Name: "var", Func: Var},
+		{Name: "video", Func: Video},
 	}
 
-	for name, fn := range cases {
-		t.Run(fmt.Sprintf("should output %v", name), func(t *testing.T) {
-			n := fn(g.Attr("id", "hat"))
-			assert.Equal(t, fmt.Sprintf(`<%v id="hat"></%v>`, name, name), n)
+	for _, test := range tests {
+		t.Run(test.Name, func(t *testing.T) {
+			n := test.Func(g.Attr("id", "hat"))
+			assert.Equal(t, fmt.Sprintf(`<%v id="hat"></%v>`, test.Name, test.Name), n)
 		})
 	}
 }
 
 func TestSimpleVoidKindElements(t *testing.T) {
-	cases := map[string]func(...g.Node) g.Node{
-		"area":   Area,
-		"base":   Base,
-		"br":     Br,
-		"col":    Col,
-		"embed":  Embed,
-		"hr":     Hr,
-		"img":    Img,
-		"input":  Input,
-		"link":   Link,
-		"meta":   Meta,
-		"param":  Param,
-		"source": Source,
-		"wbr":    Wbr,
+	tests := []struct {
+		Name string
+		Func func(...g.Node) g.Node
+	}{
+		{Name: "area", Func: Area},
+		{Name: "base", Func: Base},
+		{Name: "br", Func: Br},
+		{Name: "col", Func: Col},
+		{Name: "embed", Func: Embed},
+		{Name: "hr", Func: Hr},
+		{Name: "img", Func: Img},
+		{Name: "input", Func: Input},
+		{Name: "link", Func: Link},
+		{Name: "meta", Func: Meta},
+		{Name: "param", Func: Param},
+		{Name: "source", Func: Source},
+		{Name: "wbr", Func: Wbr},
 	}
 
-	for name, fn := range cases {
-		t.Run(fmt.Sprintf("should output %v", name), func(t *testing.T) {
-			n := fn(g.Attr("id", "hat"))
-			assert.Equal(t, fmt.Sprintf(`<%v id="hat">`, name), n)
+	for _, test := range tests {
+		t.Run(test.Name, func(t *testing.T) {
+			n := test.Func(g.Attr("id", "hat"))
+			assert.Equal(t, fmt.Sprintf(`<%v id="hat">`, test.Name), n)
 		})
 	}
 }