about summary refs log tree commit diff stats
path: root/html/attributes_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'html/attributes_test.go')
-rw-r--r--html/attributes_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/html/attributes_test.go b/html/attributes_test.go
new file mode 100644
index 0000000..7bf45bb
--- /dev/null
+++ b/html/attributes_test.go
@@ -0,0 +1,73 @@
+package html_test
+
+import (
+	"fmt"
+	"testing"
+
+	g "github.com/maragudk/gomponents"
+	"github.com/maragudk/gomponents/assert"
+	. "github.com/maragudk/gomponents/html"
+)
+
+func TestBooleanAttributes(t *testing.T) {
+	cases := map[string]func() g.Node{
+		"async":     Async,
+		"autofocus": AutoFocus,
+		"autoplay":  AutoPlay,
+		"controls":  Controls,
+		"defer":     Defer,
+		"disabled":  Disabled,
+		"multiple":  Multiple,
+		"readonly":  ReadOnly,
+		"required":  Required,
+		"selected":  Selected,
+	}
+
+	for name, fn := range cases {
+		t.Run(fmt.Sprintf("should output %v", name), func(t *testing.T) {
+			n := g.El("div", fn())
+			assert.Equal(t, fmt.Sprintf(`<div %v></div>`, name), n)
+		})
+	}
+}
+
+func TestSimpleAttributes(t *testing.T) {
+	cases := map[string]func(string) g.Node{
+		"accept":       Accept,
+		"autocomplete": AutoComplete,
+		"charset":      Charset,
+		"class":        Class,
+		"cols":         Cols,
+		"content":      Content,
+		"form":         FormAttr,
+		"height":       Height,
+		"href":         Href,
+		"id":           ID,
+		"lang":         Lang,
+		"max":          Max,
+		"maxlength":    MaxLength,
+		"min":          Min,
+		"minlength":    MinLength,
+		"name":         Name,
+		"pattern":      Pattern,
+		"preload":      Preload,
+		"placeholder":  Placeholder,
+		"rel":          Rel,
+		"rows":         Rows,
+		"src":          Src,
+		"style":        StyleAttr,
+		"tabindex":     TabIndex,
+		"target":       Target,
+		"title":        TitleAttr,
+		"type":         Type,
+		"value":        Value,
+		"width":        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"></div>`, name), n)
+		})
+	}
+}