1
0
Fork 0

Sets test

This commit is contained in:
Gregory Eremin 2018-11-08 23:28:27 +01:00
parent ad3be07ad1
commit ff91136fab
2 changed files with 47 additions and 0 deletions

33
tests/special_test.go Normal file
View File

@ -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)
})
}
}

View File

@ -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{})