hatmill/attribute/generated_test.go

67 lines
1.9 KiB
Go
Raw Normal View History

2019-05-30 03:33:30 +00:00
package attribute_test
import (
2019-05-30 03:42:48 +00:00
"testing"
2019-05-30 03:33:30 +00:00
2019-05-30 03:42:48 +00:00
"gitlab.codemonkeysoftware.net/b/hatmill"
"gitlab.codemonkeysoftware.net/b/hatmill/attribute"
2019-05-30 03:33:30 +00:00
)
func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string) {
2019-05-30 03:42:48 +00:00
t.Helper()
if attrib.ValueString() != expectedValue {
t.Fatalf("expected attribute value to be %#v, but got %#v", expectedValue, attrib.ValueString())
2019-05-30 03:42:48 +00:00
}
2019-05-30 03:33:30 +00:00
}
func TestString(t *testing.T) {
2019-05-30 03:42:48 +00:00
const s = "abcdefg"
testAttribValue(t, attribute.Id(s), s)
2019-05-30 03:33:30 +00:00
}
func TestBool(t *testing.T) {
2019-05-30 03:42:48 +00:00
testAttribValue(t, attribute.Disabled(), "")
2019-05-30 03:33:30 +00:00
}
func TestExplicitBool(t *testing.T) {
2019-05-30 03:42:48 +00:00
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")
})
2019-05-30 03:33:30 +00:00
}
func TestInt(t *testing.T) {
2019-05-30 03:42:48 +00:00
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")
})
2019-05-30 03:33:30 +00:00
}
func TestFloat(t *testing.T) {
2019-05-30 03:42:48 +00:00
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)
})
}
2019-05-30 03:33:30 +00:00
}