diff --git a/tests/special_test.go b/tests/special_test.go new file mode 100644 index 0000000..2c2acfd --- /dev/null +++ b/tests/special_test.go @@ -0,0 +1,33 @@ +package tests + +import ( + "testing" + + "github.com/localhots/bocadillo/mysql" +) + +func TestSet(t *testing.T) { + tbl := suite.createTable(mysql.ColumnTypeSet, "'a', 'b', 'c'", attrNone) + defer tbl.drop(t) + + const ( + // TODO: How do I define such a bitmask properly? + bA int64 = 1 + bB int64 = 2 + bC int64 = 4 + ) + + inputs := map[string]int64{ + "": 0, + "a": bA, + "a,b": bA | bB, + "a,c": bA | bC, + "a,b,c": bA | bB | bC, + } + + for in, exp := range inputs { + t.Run("input "+in, func(t *testing.T) { + suite.insertAndCompareExp(t, tbl, in, exp) + }) + } +} diff --git a/tests/suite_test.go b/tests/suite_test.go index 5fbfe25..343042e 100644 --- a/tests/suite_test.go +++ b/tests/suite_test.go @@ -153,6 +153,8 @@ func colTypeSyntax(ct mysql.ColumnType) (typName, attrs string) { case mysql.ColumnTypeLongblob: return "LONGBLOB", "" + case mysql.ColumnTypeSet: + return "SET", "" default: panic(fmt.Errorf("Syntax not defined for %s", ct.String())) } @@ -162,6 +164,18 @@ func colTypeSyntax(ct mysql.ColumnType) (typName, attrs string) { // Expectations // +func (s *testSuite) insertAndCompare(t *testing.T, tbl *table, val interface{}) { + t.Helper() + tbl.insert(t, val) + suite.expectValue(t, tbl, val) +} + +func (s *testSuite) insertAndCompareExp(t *testing.T, tbl *table, val, exp interface{}) { + t.Helper() + tbl.insert(t, val) + suite.expectValue(t, tbl, exp) +} + func (s *testSuite) expectValue(t *testing.T, tbl *table, exp interface{}) { t.Helper() out := make(chan interface{})