Repository: maragudk/gomponents
Pull request #20 (2020-09-24 19:54:18)

Add space before auto-closing element

codecov[bot]: # [Codecov](https://codecov.io/gh/maragudk/gomponents/pull/20?src=pr&el=h1) Report
> Merging [#20](https://codecov.io/gh/maragudk/gomponents/pull/20?src=pr&el=desc) into [master](https://codecov.io/gh/maragudk/gomponents/commit/5929ba8c41859ca9ea4117f42525e7be370ff55f?el=desc) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/maragudk/gomponents/pull/20/graphs/tree.svg?width=650&height=150&src=pr&token=JYN032TYAC)](https://codecov.io/gh/maragudk/gomponents/pull/20?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##            master       #20   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          106       106           
=========================================
  Hits           106       106           
```


| [Impacted Files](https://codecov.io/gh/maragudk/gomponents/pull/20?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [gomponents.go](https://codecov.io/gh/maragudk/gomponents/pull/20/diff?src=pr&el=tree#diff-Z29tcG9uZW50cy5nbw==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/maragudk/gomponents/pull/20?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/maragudk/gomponents/pull/20?src=pr&el=footer). Last update [5929ba8...61fdee1](https://codecov.io/gh/maragudk/gomponents/pull/20?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/gomponents.go b/gomponents.go
index 73d0545..09ec0c4 100644
--- a/gomponents.go
+++ b/gomponents.go
@@ -59,7 +59,7 @@ func El(name string, children ...Node) NodeFunc {
 		b.WriteString(name)
 
 		if len(children) == 0 {
-			b.WriteString("/>")
+			b.WriteString(" />")
 			return b.String()
 		}
 
@@ -80,7 +80,7 @@ func El(name string, children ...Node) NodeFunc {
 		b.WriteString(inside.String())
 
 		if outside.Len() == 0 {
-			b.WriteString("/>")
+			b.WriteString(" />")
 			return b.String()
 		}
 


Test patch:
diff --git a/attr/attributes_test.go b/attr/attributes_test.go
index 4da28e3..c2ddff0 100644
--- a/attr/attributes_test.go
+++ b/attr/attributes_test.go
@@ -32,7 +32,7 @@ func TestClasses(t *testing.T) {
 
 	t.Run("renders as attribute in an element", func(t *testing.T) {
 		e := g.El("div", attr.Classes{"hat": true})
-		assert.Equal(t, `<div class="hat"/>`, e)
+		assert.Equal(t, `<div class="hat" />`, e)
 	})
 
 	t.Run("also works with fmt", func(t *testing.T) {
diff --git a/attr/forms_test.go b/attr/forms_test.go
index 3ff077b..d222464 100644
--- a/attr/forms_test.go
+++ b/attr/forms_test.go
@@ -11,6 +11,6 @@ import (
 func TestForms(t *testing.T) {
 	t.Run("adds placeholder and required attributes", func(t *testing.T) {
 		e := g.El("input", attr.Placeholder("hat"), attr.Required())
-		assert.Equal(t, `<input placeholder="hat" required/>`, e)
+		assert.Equal(t, `<input placeholder="hat" required />`, e)
 	})
 }
diff --git a/el/elements_test.go b/el/elements_test.go
index a24e963..a5e8647 100644
--- a/el/elements_test.go
+++ b/el/elements_test.go
@@ -10,25 +10,25 @@ import (
 
 func TestDocument(t *testing.T) {
 	t.Run("returns doctype and children", func(t *testing.T) {
-		assert.Equal(t, `<!doctype html><html/>`, el.Document(g.El("html")))
+		assert.Equal(t, `<!doctype html><html />`, el.Document(g.El("html")))
 	})
 }
 
 func TestHTML(t *testing.T) {
 	t.Run("returns an html element", func(t *testing.T) {
-		assert.Equal(t, "<html><div/><span/></html>", el.HTML(g.El("div"), g.El("span")))
+		assert.Equal(t, "<html><div /><span /></html>", el.HTML(g.El("div"), g.El("span")))
 	})
 }
 
 func TestHead(t *testing.T) {
 	t.Run("returns a head element", func(t *testing.T) {
-		assert.Equal(t, "<head><title/><link/></head>", el.Head(g.El("title"), g.El("link")))
+		assert.Equal(t, "<head><title /><link /></head>", el.Head(g.El("title"), g.El("link")))
 	})
 }
 
 func TestBody(t *testing.T) {
 	t.Run("returns a body element", func(t *testing.T) {
-		assert.Equal(t, "<body><div/><span/></body>", el.Body(g.El("div"), g.El("span")))
+		assert.Equal(t, "<body><div /><span /></body>", el.Body(g.El("div"), g.El("span")))
 	})
 }
 
@@ -40,25 +40,25 @@ func TestTitle(t *testing.T) {
 
 func TestMeta(t *testing.T) {
 	t.Run("returns a meta element", func(t *testing.T) {
-		assert.Equal(t, `<meta charset="utf-8"/>`, el.Meta(g.Attr("charset", "utf-8")))
+		assert.Equal(t, `<meta charset="utf-8" />`, el.Meta(g.Attr("charset", "utf-8")))
 	})
 }
 
 func TestLink(t *testing.T) {
 	t.Run("returns a link element", func(t *testing.T) {
-		assert.Equal(t, `<link rel="stylesheet"/>`, el.Link(g.Attr("rel", "stylesheet")))
+		assert.Equal(t, `<link rel="stylesheet" />`, el.Link(g.Attr("rel", "stylesheet")))
 	})
 }
 
 func TestStyle(t *testing.T) {
 	t.Run("returns a style element", func(t *testing.T) {
-		assert.Equal(t, `<style type="text/css"/>`, el.Style(g.Attr("type", "text/css")))
+		assert.Equal(t, `<style type="text/css" />`, el.Style(g.Attr("type", "text/css")))
 	})
 }
 
 func TestDiv(t *testing.T) {
 	t.Run("returns a div element", func(t *testing.T) {
-		assert.Equal(t, `<div><span/></div>`, el.Div(el.Span()))
+		assert.Equal(t, `<div><span /></div>`, el.Div(el.Span()))
 	})
 }
 
@@ -118,13 +118,13 @@ func TestH6(t *testing.T) {
 
 func TestOl(t *testing.T) {
 	t.Run("returns an ol element", func(t *testing.T) {
-		assert.Equal(t, `<ol><li/></ol>`, el.Ol(el.Li()))
+		assert.Equal(t, `<ol><li /></ol>`, el.Ol(el.Li()))
 	})
 }
 
 func TestUl(t *testing.T) {
 	t.Run("returns a ul element", func(t *testing.T) {
-		assert.Equal(t, `<ul><li/></ul>`, el.Ul(el.Li()))
+		assert.Equal(t, `<ul><li /></ul>`, el.Ul(el.Li()))
 	})
 }
 
@@ -160,6 +160,6 @@ func TestEm(t *testing.T) {
 
 func TestImg(t *testing.T) {
 	t.Run("returns an img element with href and alt attributes", func(t *testing.T) {
-		assert.Equal(t, `<img src="hat.png" alt="hat" id="image"/>`, el.Img("hat.png", "hat", g.Attr("id", "image")))
+		assert.Equal(t, `<img src="hat.png" alt="hat" id="image" />`, el.Img("hat.png", "hat", g.Attr("id", "image")))
 	})
 }
diff --git a/el/forms_test.go b/el/forms_test.go
index 65f2fae..2f43036 100644
--- a/el/forms_test.go
+++ b/el/forms_test.go
@@ -10,19 +10,19 @@ import (
 
 func TestButton(t *testing.T) {
 	t.Run("returns a button element", func(t *testing.T) {
-		assert.Equal(t, `<button/>`, el.Button())
+		assert.Equal(t, `<button />`, el.Button())
 	})
 }
 
 func TestForm(t *testing.T) {
 	t.Run("returns a form element with action and method attributes", func(t *testing.T) {
-		assert.Equal(t, `<form action="/" method="post"/>`, el.Form("/", "post"))
+		assert.Equal(t, `<form action="/" method="post" />`, el.Form("/", "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 type="text" name="hat"/>`, el.Input("text", "hat"))
+		assert.Equal(t, `<input type="text" name="hat" />`, el.Input("text", "hat"))
 	})
 }
 
@@ -40,7 +40,7 @@ func TestOption(t *testing.T) {
 
 func TestProgress(t *testing.T) {
 	t.Run("returns a progress element with attributes value and max", func(t *testing.T) {
-		assert.Equal(t, `<progress value="5.5" max="10"/>`, el.Progress(5.5, 10))
+		assert.Equal(t, `<progress value="5.5" max="10" />`, el.Progress(5.5, 10))
 	})
 }
 
@@ -53,6 +53,6 @@ func TestSelect(t *testing.T) {
 
 func TestTextarea(t *testing.T) {
 	t.Run("returns a textarea element with attribute name", func(t *testing.T) {
-		assert.Equal(t, `<textarea name="hat"/>`, el.Textarea("hat"))
+		assert.Equal(t, `<textarea name="hat" />`, el.Textarea("hat"))
 	})
 }
diff --git a/gomponents_test.go b/gomponents_test.go
index 65b82b5..0e397cb 100644
--- a/gomponents_test.go
+++ b/gomponents_test.go
@@ -61,22 +61,22 @@ func (o outsider) Render() string {
 func TestEl(t *testing.T) {
 	t.Run("renders an empty element if no children given", func(t *testing.T) {
 		e := g.El("div")
-		assert.Equal(t, "<div/>", e)
+		assert.Equal(t, "<div />", e)
 	})
 
 	t.Run("renders an empty element if only attributes given as children", func(t *testing.T) {
 		e := g.El("div", g.Attr("class", "hat"))
-		assert.Equal(t, `<div class="hat"/>`, e)
+		assert.Equal(t, `<div class="hat" />`, e)
 	})
 
 	t.Run("renders an element, attributes, and element children", func(t *testing.T) {
 		e := g.El("div", g.Attr("class", "hat"), g.El("span"))
-		assert.Equal(t, `<div class="hat"><span/></div>`, e)
+		assert.Equal(t, `<div class="hat"><span /></div>`, e)
 	})
 
 	t.Run("renders attributes at the correct place regardless of placement in parameter list", func(t *testing.T) {
 		e := g.El("div", g.El("span"), g.Attr("class", "hat"))
-		assert.Equal(t, `<div class="hat"><span/></div>`, e)
+		assert.Equal(t, `<div class="hat"><span /></div>`, e)
 	})
 
 	t.Run("renders outside if node does not implement placer", func(t *testing.T) {
@@ -87,22 +87,22 @@ func TestEl(t *testing.T) {
 
 func TestText(t *testing.T) {
 	t.Run("renders escaped text", func(t *testing.T) {
-		e := g.Text("<div/>")
-		assert.Equal(t, "&lt;div/&gt;", e)
+		e := g.Text("<div />")
+		assert.Equal(t, "&lt;div /&gt;", e)
 	})
 }
 
 func TestTextf(t *testing.T) {
 	t.Run("renders interpolated and escaped text", func(t *testing.T) {
-		e := g.Textf("<%v/>", "div")
-		assert.Equal(t, "&lt;div/&gt;", e)
+		e := g.Textf("<%v />", "div")
+		assert.Equal(t, "&lt;div /&gt;", e)
 	})
 }
 
 func TestRaw(t *testing.T) {
 	t.Run("renders raw text", func(t *testing.T) {
-		e := g.Raw("<div/>")
-		assert.Equal(t, "<div/>", e)
+		e := g.Raw("<div />")
+		assert.Equal(t, "<div />", e)
 	})
 }