about summary refs log tree commit diff stats
path: root/attr/simple_test.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-10-28 16:59:04 +0100
committerGitHub2020-10-28 16:59:04 +0100
commit13701c4f668eba27956a8ac554a1fe272245d210 (patch)
treeb123bbbedaa1fe8f666ce3981fead6e884dd0b74 /attr/simple_test.go
parent18e90339fcac48806a5777766aeb256be2b8c4bc (diff)
downloadgomponents-13701c4f668eba27956a8ac554a1fe272245d210.tar.lz
gomponents-13701c4f668eba27956a8ac554a1fe272245d210.tar.zst
gomponents-13701c4f668eba27956a8ac554a1fe272245d210.zip
Add attribute helpers (#35)
Also refactor tests to be table-driven, for readability.
Diffstat (limited to 'attr/simple_test.go')
-rw-r--r--attr/simple_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/attr/simple_test.go b/attr/simple_test.go
new file mode 100644
index 0000000..784561a
--- /dev/null
+++ b/attr/simple_test.go
@@ -0,0 +1,47 @@
+package attr_test
+
+import (
+	"fmt"
+	"testing"
+
+	g "github.com/maragudk/gomponents"
+	"github.com/maragudk/gomponents/assert"
+	"github.com/maragudk/gomponents/attr"
+)
+
+func TestSimpleAttributes(t *testing.T) {
+	cases := map[string]func(string) g.Node{
+		"accept":       attr.Accept,
+		"autocomplete": attr.AutoComplete,
+		"class":        attr.Class,
+		"form":         attr.Form,
+		"height":       attr.Height,
+		"href":         attr.Href,
+		"id":           attr.ID,
+		"lang":         attr.Lang,
+		"max":          attr.Max,
+		"maxlength":    attr.MaxLength,
+		"min":          attr.Min,
+		"minlength":    attr.MinLength,
+		"name":         attr.Name,
+		"pattern":      attr.Pattern,
+		"preload":      attr.Preload,
+		"placeholder":  attr.Placeholder,
+		"rel":          attr.Rel,
+		"src":          attr.Src,
+		"style":        attr.Style,
+		"tabindex":     attr.TabIndex,
+		"target":       attr.Target,
+		"title":        attr.Title,
+		"type":         attr.Type,
+		"value":        attr.Value,
+		"width":        attr.Width,
+	}
+
+	for name, fn := range cases {
+		t.Run(fmt.Sprintf(`should output %v="hat"`, name), func(t *testing.T) {
+			n := g.El("div", fn("hat"))
+			assert.Equal(t, fmt.Sprintf(`<div %v="hat" />`, name), n)
+		})
+	}
+}