Sets test
This commit is contained in:
parent
ad3be07ad1
commit
ff91136fab
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -153,6 +153,8 @@ func colTypeSyntax(ct mysql.ColumnType) (typName, attrs string) {
|
||||||
case mysql.ColumnTypeLongblob:
|
case mysql.ColumnTypeLongblob:
|
||||||
return "LONGBLOB", ""
|
return "LONGBLOB", ""
|
||||||
|
|
||||||
|
case mysql.ColumnTypeSet:
|
||||||
|
return "SET", ""
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("Syntax not defined for %s", ct.String()))
|
panic(fmt.Errorf("Syntax not defined for %s", ct.String()))
|
||||||
}
|
}
|
||||||
|
@ -162,6 +164,18 @@ func colTypeSyntax(ct mysql.ColumnType) (typName, attrs string) {
|
||||||
// Expectations
|
// 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{}) {
|
func (s *testSuite) expectValue(t *testing.T, tbl *table, exp interface{}) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
out := make(chan interface{})
|
out := make(chan interface{})
|
||||||
|
|
Loading…
Reference in New Issue