forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolumn_test.go
90 lines (78 loc) · 2.09 KB
/
column_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 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),
},
}
}