From ff91136fabe5dd012be587b3b31a492e272a535b Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Thu, 8 Nov 2018 23:28:27 +0100 Subject: [PATCH] Sets test --- tests/special_test.go | 33 +++++++++++++++++++++++++++++++++ tests/suite_test.go | 14 ++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/special_test.go 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{})