Files
tidb/column/column_test.go
Ewan Chou a80d131c06 util/types, column, expressions: use types.Convert to replace Col.CastValue
The two methods has similar functionality and has complex logic, after this change,
the code base would be easier to maintain.

For `CAST` function, the behaviour is different than the general purpose `types.Convert`,
so I implemented a dedicated function for it.
2015-09-10 20:11:40 +08:00

91 lines
2.1 KiB
Go

// Copyright 2015 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package column
import (
"testing"
. "github.com/pingcap/check"
"github.com/pingcap/tidb/model"
mysql "github.com/pingcap/tidb/mysqldef"
"github.com/pingcap/tidb/util/types"
)
var _ = Suite(&testColumnSuite{})
func TestT(t *testing.T) {
TestingT(t)
}
type testColumnSuite struct{}
func (s *testColumnSuite) TestString(c *C) {
col := &Col{
model.ColumnInfo{
FieldType: *types.NewFieldType(mysql.TypeTiny),
},
}
col.Flen = 2
col.getTypeStr()
col.Decimal = 1
col.Charset = mysql.DefaultCharset
col.Collate = mysql.DefaultCollationName
col.Flag |= mysql.ZerofillFlag | mysql.UnsignedFlag | mysql.BinaryFlag | mysql.AutoIncrementFlag | mysql.NotNullFlag
col.getTypeStr()
cs := col.String()
c.Assert(len(cs), Greater, 0)
}
func (s *testColumnSuite) TestFind(c *C) {
cols := []*Col{
newCol("a"),
newCol("b"),
newCol("c"),
}
FindCols(cols, []string{"a"})
FindCols(cols, []string{"d"})
cols[0].Flag |= mysql.OnUpdateNowFlag
FindOnUpdateCols(cols)
}
func (s *testColumnSuite) TestCheck(c *C) {
col := newCol("a")
col.Flag = mysql.AutoIncrementFlag
cols := []*Col{col, col}
CheckOnce(cols)
cols = cols[:1]
CheckNotNull(cols, []interface{}{nil})
cols[0].Flag |= mysql.NotNullFlag
CheckNotNull(cols, []interface{}{nil})
}
func (s *testColumnSuite) TestDesc(c *C) {
col := newCol("a")
col.Flag = mysql.AutoIncrementFlag | mysql.NotNullFlag | mysql.PriKeyFlag
NewColDesc(col)
col.Flag = mysql.MultipleKeyFlag
NewColDesc(col)
ColDescFieldNames(false)
ColDescFieldNames(true)
}
func newCol(name string) *Col {
return &Col{
model.ColumnInfo{
Name: model.NewCIStr(name),
},
}
}