more tests
This commit is contained in:
parent
3c4583c2b3
commit
e5c5014812
2 changed files with 39 additions and 2 deletions
|
|
@ -17,9 +17,13 @@ func (m *AttributeMapOrdered) Set(key string, value any) {
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case string:
|
case string:
|
||||||
m.data.Set(key, v)
|
m.data.Set(key, v)
|
||||||
|
case *AttributeMap:
|
||||||
|
for k, v2 := range *v {
|
||||||
|
m.Set(k, v2)
|
||||||
|
}
|
||||||
case *AttributeMapOrdered:
|
case *AttributeMapOrdered:
|
||||||
v.Each(func(k string, v string) {
|
v.Each(func(k string, v2 string) {
|
||||||
m.Set(k, v)
|
m.Set(k, v2)
|
||||||
})
|
})
|
||||||
case *AttributeR:
|
case *AttributeR:
|
||||||
m.data.Set(v.Name, v.Value)
|
m.data.Set(v.Name, v.Value)
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,39 @@ func TestRenderAttributes_1(t *testing.T) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenderAttributes_2(t *testing.T) {
|
||||||
|
div := Div(
|
||||||
|
AttributePairs("class", "bg-red-500", "id", "my-div"),
|
||||||
|
Button(
|
||||||
|
AttributePairs("class", "bg-blue-500", "id", "my-button"),
|
||||||
|
Text("Click me"),
|
||||||
|
Attribute("disabled", "true"),
|
||||||
|
Attribute("data-attr", "value"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert.Equal(t,
|
||||||
|
`<div class="bg-red-500" id="my-div"><button class="bg-blue-500" id="my-button" disabled="true" data-attr="value">Click me</button></div>`,
|
||||||
|
Render(div))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderEmptyDiv(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
assert.Equal(t,
|
||||||
|
`<div></div>`,
|
||||||
|
Render(Div()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRenderVoidElement(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
assert.Equal(t,
|
||||||
|
`<input type="text"/>`,
|
||||||
|
Render(Input("text")),
|
||||||
|
)
|
||||||
|
assert.Equal(t, `<input/>`, Render(Tag("input")))
|
||||||
|
}
|
||||||
|
|
||||||
func TestRawContent(t *testing.T) {
|
func TestRawContent(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
str := "<div>hello, world</div>"
|
str := "<div>hello, world</div>"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue