From 3b7dceab897709fe8243c605adea90ee771c49ff Mon Sep 17 00:00:00 2001
From: Markus Wüstenberg
Date: Wed, 5 May 2021 09:03:16 +0200
Subject: Streamline HTML element API (#66)
There were a lot of elements previously, like `Em`, `H1`, and a lot more, that took a string as the first argument previously. This was weird when you wanted to mix elements to output html like `…` or `
Something something something
`. gomponents is not an HTML validator, so I want people to be able to use elements however they please, also without text content.
This also means that all elements now have the same API.---
html/elements_test.go | 72 +++++++++++++++++++++------------------------------
1 file changed, 30 insertions(+), 42 deletions(-)
(limited to 'html/elements_test.go')
diff --git a/html/elements_test.go b/html/elements_test.go
index 83742c4..a85312c 100644
--- a/html/elements_test.go
+++ b/html/elements_test.go
@@ -30,36 +30,55 @@ 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,
@@ -72,12 +91,19 @@ func TestSimpleElements(t *testing.T) {
"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,
@@ -86,8 +112,12 @@ func TestSimpleElements(t *testing.T) {
"tfoot": TFoot,
"th": Th,
"thead": THead,
+ "time": Time,
+ "title": TitleEl,
"tr": Tr,
+ "u": U,
"ul": Ul,
+ "var": Var,
}
for name, fn := range cases {
@@ -122,45 +152,3 @@ func TestSimpleVoidKindElements(t *testing.T) {
})
}
}
-
-func TestTextElements(t *testing.T) {
- cases := map[string]func(string, ...g.Node) g.Node{
- "abbr": Abbr,
- "b": B,
- "caption": Caption,
- "dd": Dd,
- "del": Del,
- "dfn": Dfn,
- "dt": Dt,
- "em": Em,
- "figcaption": FigCaption,
- "h1": H1,
- "h2": H2,
- "h3": H3,
- "h4": H4,
- "h5": H5,
- "h6": H6,
- "i": I,
- "ins": Ins,
- "kbd": Kbd,
- "mark": Mark,
- "q": Q,
- "s": S,
- "samp": Samp,
- "small": Small,
- "strong": Strong,
- "sub": Sub,
- "sup": Sup,
- "time": Time,
- "title": TitleEl,
- "u": U,
- "var": Var,
- }
-
- for name, fn := range cases {
- t.Run(fmt.Sprintf("should output %v", name), func(t *testing.T) {
- n := fn("hat", g.Attr("id", "hat"))
- assert.Equal(t, fmt.Sprintf(`<%v id="hat">hat%v>`, name, name), n)
- })
- }
-}
--
cgit 1.4.1