Created SpaceList type
This commit is contained in:
parent
0e29901b4f
commit
287d0036f3
@ -19,7 +19,7 @@ func Accept(value ...string) hatmill.Attrib {
|
||||
func AcceptCharset(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "accept-charset",
|
||||
Value: String(strings.Join(value, " ")),
|
||||
Value: String(SpaceList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ func Cite(value string) hatmill.Attrib {
|
||||
func Class(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "class",
|
||||
Value: String(strings.Join(value, " ")),
|
||||
Value: String(SpaceList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ func Enctype(value string) hatmill.Attrib {
|
||||
func For(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "for",
|
||||
Value: String(strings.Join(value, " ")),
|
||||
Value: String(SpaceList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ func Formmethod(value string) hatmill.Attrib {
|
||||
func Headers(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "headers",
|
||||
Value: String(strings.Join(value, " ")),
|
||||
Value: String(SpaceList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -500,7 +500,7 @@ func Pattern(value string) hatmill.Attrib {
|
||||
func Ping(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "ping",
|
||||
Value: String(strings.Join(value, " ")),
|
||||
Value: String(SpaceList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -547,7 +547,7 @@ func Referrerpolicy(value string) hatmill.Attrib {
|
||||
func Rel(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "rel",
|
||||
Value: String(strings.Join(value, " ")),
|
||||
Value: String(SpaceList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -585,7 +585,7 @@ func Rowspan(value int) hatmill.Attrib {
|
||||
func Sandbox(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "sandbox",
|
||||
Value: String(strings.Join(value, " ")),
|
||||
Value: String(SpaceList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,15 +14,6 @@ func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpaceList(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
testAttribValue(t, attribute.Class(), "")
|
||||
})
|
||||
t.Run("nonempty", func(t *testing.T) {
|
||||
testAttribValue(t, attribute.Class("alpha", "bravo", "charlie"), "alpha bravo charlie")
|
||||
})
|
||||
}
|
||||
|
||||
func TestCommaList(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
testAttribValue(t, attribute.Class(), "")
|
||||
|
9
attribute/value_types.go
Normal file
9
attribute/value_types.go
Normal file
@ -0,0 +1,9 @@
|
||||
package attribute
|
||||
|
||||
import "strings"
|
||||
|
||||
type SpaceList []string
|
||||
|
||||
func (l SpaceList) String() string {
|
||||
return strings.Join(l, " ")
|
||||
}
|
24
attribute/value_types_test.go
Normal file
24
attribute/value_types_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
package attribute_test
|
||||
|
||||
import (
|
||||
"gitlab.codemonkeysoftware.net/b/hatmill/attribute"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func expectEqualStrings(t *testing.T, actual, expected string) {
|
||||
if actual != expected {
|
||||
t.Fatalf("expected %q, got %q", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpaceList(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
expectEqualStrings(t, attribute.SpaceList{}.String(), "")
|
||||
})
|
||||
|
||||
t.Run("nonempty", func(t *testing.T) {
|
||||
expected := "alpha bravo charlie"
|
||||
actual := attribute.SpaceList{"alpha", "bravo", "charlie"}.String()
|
||||
expectEqualStrings(t, actual, expected)
|
||||
})
|
||||
}
|
@ -68,8 +68,7 @@ var attribTypes = map[string]AttribTypeInfo{
|
||||
Imports: []string{"strconv"},
|
||||
},
|
||||
"space list": {
|
||||
Template: listTemplate(" "),
|
||||
Imports: []string{"strings"},
|
||||
Template: simpleTemplate("...string", "SpaceList(%s).String()"),
|
||||
},
|
||||
"comma list": {
|
||||
Template: listTemplate(","),
|
||||
|
Loading…
Reference in New Issue
Block a user