Created CommaList type
This commit is contained in:
parent
287d0036f3
commit
276c0f9c0e
@ -4,14 +4,13 @@
|
||||
package attribute
|
||||
|
||||
import "gitlab.codemonkeysoftware.net/b/hatmill"
|
||||
import "strings"
|
||||
import "strconv"
|
||||
|
||||
// Accept creates a "accept" attribute
|
||||
func Accept(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "accept",
|
||||
Value: String(strings.Join(value, ",")),
|
||||
Value: String(CommaList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -672,7 +671,7 @@ func Srclang(value string) hatmill.Attrib {
|
||||
func Srcset(value ...string) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "srcset",
|
||||
Value: String(strings.Join(value, ",")),
|
||||
Value: String(CommaList(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,15 +14,6 @@ func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommaList(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
testAttribValue(t, attribute.Class(), "")
|
||||
})
|
||||
t.Run("nonempty", func(t *testing.T) {
|
||||
testAttribValue(t, attribute.Accept("alpha", "bravo", "charlie"), "alpha,bravo,charlie")
|
||||
})
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
const s = "abcdefg"
|
||||
testAttribValue(t, attribute.Id(s), s)
|
||||
|
@ -7,3 +7,9 @@ type SpaceList []string
|
||||
func (l SpaceList) String() string {
|
||||
return strings.Join(l, " ")
|
||||
}
|
||||
|
||||
type CommaList []string
|
||||
|
||||
func (l CommaList) String() string {
|
||||
return strings.Join(l, ",")
|
||||
}
|
||||
|
@ -22,3 +22,15 @@ func TestSpaceList(t *testing.T) {
|
||||
expectEqualStrings(t, actual, expected)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCommaList(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
expectEqualStrings(t, attribute.CommaList{}.String(), "")
|
||||
})
|
||||
|
||||
t.Run("nonempty", func(t *testing.T) {
|
||||
expected := "alpha,bravo,charlie"
|
||||
actual := attribute.CommaList{"alpha", "bravo", "charlie"}.String()
|
||||
expectEqualStrings(t, actual, expected)
|
||||
})
|
||||
}
|
||||
|
@ -71,8 +71,7 @@ var attribTypes = map[string]AttribTypeInfo{
|
||||
Template: simpleTemplate("...string", "SpaceList(%s).String()"),
|
||||
},
|
||||
"comma list": {
|
||||
Template: listTemplate(","),
|
||||
Imports: []string{"strings"},
|
||||
Template: simpleTemplate("...string", "CommaList(%s).String()"),
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user