about summary refs log tree commit diff stats
path: root/el/text_test.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-10-28 16:16:18 +0100
committerGitHub2020-10-28 16:16:18 +0100
commit18e90339fcac48806a5777766aeb256be2b8c4bc (patch)
tree7b5bd103e15db8a4ed81981e6b83b0d547d34540 /el/text_test.go
parent8f17dba6f1268ab8c8810d7940d1484315cdb825 (diff)
downloadgomponents-18e90339fcac48806a5777766aeb256be2b8c4bc.tar.lz
gomponents-18e90339fcac48806a5777766aeb256be2b8c4bc.tar.zst
gomponents-18e90339fcac48806a5777766aeb256be2b8c4bc.zip
Add element helpers and refactor (#34)
This change adds a lot of element helpers, and refactors:
- helpers into simple, text, and other helpers
- most tests into table-driven tests, so they're easier to read

Thanks to @oderwat for pushing me to improve the tests. 😉
Diffstat (limited to 'el/text_test.go')
-rw-r--r--el/text_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/el/text_test.go b/el/text_test.go
new file mode 100644
index 0000000..a751e19
--- /dev/null
+++ b/el/text_test.go
@@ -0,0 +1,52 @@
+package el_test
+
+import (
+	"fmt"
+	"testing"
+
+	g "github.com/maragudk/gomponents"
+	"github.com/maragudk/gomponents/assert"
+	"github.com/maragudk/gomponents/el"
+)
+
+func TestTextElements(t *testing.T) {
+	cases := map[string]func(string, ...g.Node) g.NodeFunc{
+		"abbr":       el.Abbr,
+		"b":          el.B,
+		"caption":    el.Caption,
+		"dd":         el.Dd,
+		"del":        el.Del,
+		"dfn":        el.Dfn,
+		"dt":         el.Dt,
+		"em":         el.Em,
+		"figcaption": el.FigCaption,
+		"h1":         el.H1,
+		"h2":         el.H2,
+		"h3":         el.H3,
+		"h4":         el.H4,
+		"h5":         el.H5,
+		"h6":         el.H6,
+		"i":          el.I,
+		"ins":        el.Ins,
+		"kbd":        el.Kbd,
+		"mark":       el.Mark,
+		"q":          el.Q,
+		"s":          el.S,
+		"samp":       el.Samp,
+		"small":      el.Small,
+		"strong":     el.Strong,
+		"sub":        el.Sub,
+		"sup":        el.Sup,
+		"time":       el.Time,
+		"title":      el.Title,
+		"u":          el.U,
+		"var":        el.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)
+		})
+	}
+}