From a76262652b227c95ce140f3698c46f59b79354ac Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Thu, 10 Dec 2020 13:00:23 +0100 Subject: Move elements and attributes into html package (#52) This makes it easier to use dot-imports. Also updated the readme and examples with new usage, and move the `Classes` helper into the `components` package.--- html/attributes_test.go | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 html/attributes_test.go (limited to 'html/attributes_test.go') 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(`
`, 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(`
`, name), n) + }) + } +} -- cgit 1.4.1