about summary refs log tree commit diff stats
path: root/html/elements_test.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2021-05-05 09:03:16 +0200
committerGitHub2021-05-05 09:03:16 +0200
commit3b7dceab897709fe8243c605adea90ee771c49ff (patch)
tree78e5fd6151111dca6f60e9e365c79b897e0c4bca /html/elements_test.go
parent5d2f0f1b87aff69edf5b3a993afbb1ae2db946d0 (diff)
downloadgomponents-3b7dceab897709fe8243c605adea90ee771c49ff.tar.lz
gomponents-3b7dceab897709fe8243c605adea90ee771c49ff.tar.zst
gomponents-3b7dceab897709fe8243c605adea90ee771c49ff.zip
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 `<strong><em>…</em></strong>` or `<h1>Something <em>something</em> something</h1>`. 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.
Diffstat (limited to 'html/elements_test.go')
-rw-r--r--html/elements_test.go72
1 files changed, 30 insertions, 42 deletions
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)
-		})
-	}
-}