Created Bool type
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
package attribute
|
||||
|
||||
import "gitlab.codemonkeysoftware.net/b/hatmill"
|
||||
import "strconv"
|
||||
|
||||
// Accept creates a "accept" attribute
|
||||
func Accept(value ...string) hatmill.Attrib {
|
||||
@ -134,7 +133,7 @@ func Content(value string) hatmill.Attrib {
|
||||
func Contenteditable(value bool) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "contenteditable",
|
||||
Value: String(strconv.FormatBool(value)),
|
||||
Value: String(Bool(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,7 +225,7 @@ func Download(value string) hatmill.Attrib {
|
||||
func Draggable(value bool) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "draggable",
|
||||
Value: String(strconv.FormatBool(value)),
|
||||
Value: String(Bool(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -639,7 +638,7 @@ func Span(value int) hatmill.Attrib {
|
||||
func Spellcheck(value bool) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "spellcheck",
|
||||
Value: String(strconv.FormatBool(value)),
|
||||
Value: String(Bool(value).String()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,3 @@ func TestString(t *testing.T) {
|
||||
func TestBool(t *testing.T) {
|
||||
testAttribValue(t, attribute.Disabled(), "")
|
||||
}
|
||||
|
||||
func TestExplicitBool(t *testing.T) {
|
||||
t.Run("true", func(t *testing.T) {
|
||||
testAttribValue(t, attribute.Draggable(true), "true")
|
||||
})
|
||||
t.Run("false", func(t *testing.T) {
|
||||
testAttribValue(t, attribute.Draggable(false), "false")
|
||||
})
|
||||
}
|
||||
|
@ -26,3 +26,9 @@ type Int int
|
||||
func (n Int) String() string {
|
||||
return strconv.FormatInt(int64(n), 10)
|
||||
}
|
||||
|
||||
type Bool bool
|
||||
|
||||
func (b Bool) String() string {
|
||||
return strconv.FormatBool(bool(b))
|
||||
}
|
||||
|
@ -67,3 +67,12 @@ func TestInt(t *testing.T) {
|
||||
expectEqualStrings(t, attribute.Int(-45).String(), "-45")
|
||||
})
|
||||
}
|
||||
|
||||
func TestExplicitBool(t *testing.T) {
|
||||
t.Run("true", func(t *testing.T) {
|
||||
expectEqualStrings(t, attribute.Bool(true).String(), "true")
|
||||
})
|
||||
t.Run("false", func(t *testing.T) {
|
||||
expectEqualStrings(t, attribute.Bool(false).String(), "false")
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user