hatmill/attribute/generated_test.go

85 lines
2.4 KiB
Go

package attribute_test
import (
"testing"
"gitlab.codemonkeysoftware.net/b/hatmill"
"gitlab.codemonkeysoftware.net/b/hatmill/attribute"
)
func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string) {
t.Helper()
if attrib.Value != expectedValue {
t.Fatalf("expected attribute value to be %#v, but got %#v", expectedValue, attrib.Value)
}
}
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(), "")
})
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)
}
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")
})
}
func TestInt(t *testing.T) {
t.Run("zero", func(t *testing.T) {
testAttribValue(t, attribute.Height(0), "0")
})
t.Run("positive", func(t *testing.T) {
testAttribValue(t, attribute.Height(45), "45")
})
t.Run("negative", func(t *testing.T) {
testAttribValue(t, attribute.Tabindex(-45), "-45")
})
}
func TestFloat(t *testing.T) {
for _, testcase := range []struct {
name string
f float32
value string
}{
{name: "zero", f: 0, value: "0"},
{name: "integral", f: 45, value: "45"},
{name: "positive fractional, small positive exponent", f: 12.55, value: "12.55"},
{name: "positive fractional, large positive exponent", f: 1.55E+12, value: "1.55E+12"},
{name: "positive fractional, large negative exponent", f: 1.55E-12, value: "1.55E-12"},
{name: "negative fractional, small positive exponent", f: -12.55, value: "-12.55"},
{name: "negative fractional, large positive exponent", f: -1.55E+12, value: "-1.55E+12"},
{name: "negative fractional, large negative exponent", f: -1.55E-12, value: "-1.55E-12"},
} {
t.Run(testcase.name, func(t *testing.T) {
testAttribValue(t, attribute.Min(testcase.f), testcase.value)
})
}
}