Formatted Go code

This commit is contained in:
Brandon Dyck 2019-05-29 21:42:48 -06:00
parent 543ce1986a
commit 6f42553a9b

View File

@ -1,75 +1,75 @@
package attribute_test package attribute_test
import ( import (
"testing" "testing"
"gitlab.codemonkeysoftware.net/b/hatmill" "gitlab.codemonkeysoftware.net/b/hatmill"
"gitlab.codemonkeysoftware.net/b/hatmill/attribute" "gitlab.codemonkeysoftware.net/b/hatmill/attribute"
) )
func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string) { func testAttribValue(t *testing.T, attrib hatmill.Attrib, expectedValue string) {
t.Helper() t.Helper()
if attrib.Value != expectedValue { if attrib.Value != expectedValue {
t.Fatalf("expected attribute value to be %#v, but got %#v", expectedValue, attrib.Value) t.Fatalf("expected attribute value to be %#v, but got %#v", expectedValue, attrib.Value)
} }
} }
func TestSpaceList(t *testing.T) { func TestSpaceList(t *testing.T) {
t.Run("empty", func(t *testing.T) { t.Run("empty", func(t *testing.T) {
testAttribValue(t, attribute.Class(), "") testAttribValue(t, attribute.Class(), "")
}) })
t.Run("nonempty", func(t *testing.T) { t.Run("nonempty", func(t *testing.T) {
testAttribValue(t, attribute.Class("alpha", "bravo", "charlie"), "alpha bravo charlie") testAttribValue(t, attribute.Class("alpha", "bravo", "charlie"), "alpha bravo charlie")
}) })
} }
func TestString(t *testing.T) { func TestString(t *testing.T) {
const s = "abcdefg" const s = "abcdefg"
testAttribValue(t, attribute.Id(s), s) testAttribValue(t, attribute.Id(s), s)
} }
func TestBool(t *testing.T) { func TestBool(t *testing.T) {
testAttribValue(t, attribute.Disabled(), "") testAttribValue(t, attribute.Disabled(), "")
} }
func TestExplicitBool(t *testing.T) { func TestExplicitBool(t *testing.T) {
t.Run("true", func(t *testing.T) { t.Run("true", func(t *testing.T) {
testAttribValue(t, attribute.Draggable(true), "true") testAttribValue(t, attribute.Draggable(true), "true")
}) })
t.Run("false", func(t *testing.T) { t.Run("false", func(t *testing.T) {
testAttribValue(t, attribute.Draggable(false), "false") testAttribValue(t, attribute.Draggable(false), "false")
}) })
} }
func TestInt(t *testing.T) { func TestInt(t *testing.T) {
t.Run("zero", func(t *testing.T) { t.Run("zero", func(t *testing.T) {
testAttribValue(t, attribute.Height(0), "0") testAttribValue(t, attribute.Height(0), "0")
}) })
t.Run("positive", func(t *testing.T) { t.Run("positive", func(t *testing.T) {
testAttribValue(t, attribute.Height(45), "45") testAttribValue(t, attribute.Height(45), "45")
}) })
t.Run("negative", func(t *testing.T) { t.Run("negative", func(t *testing.T) {
testAttribValue(t, attribute.Tabindex(-45), "-45") testAttribValue(t, attribute.Tabindex(-45), "-45")
}) })
} }
func TestFloat(t *testing.T) { func TestFloat(t *testing.T) {
for _, testcase := range []struct{ for _, testcase := range []struct {
name string name string
f float32 f float32
value string value string
} { }{
{name: "zero", f: 0, value: "0"}, {name: "zero", f: 0, value: "0"},
{name: "integral", f: 45, value: "45"}, {name: "integral", f: 45, value: "45"},
{name: "positive fractional, small positive exponent", f: 12.55, value: "12.55"}, {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 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: "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, 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 positive exponent", f: -1.55E+12, value: "-1.55E+12"},
{name: "negative fractional, large negative 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) { t.Run(testcase.name, func(t *testing.T) {
testAttribValue(t, attribute.Min(testcase.f), testcase.value) testAttribValue(t, attribute.Min(testcase.f), testcase.value)
}) })
} }
} }