Skip to content

Commit

Permalink
*: rename table-driven tests name. (pingcap#3081)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored and zimulala committed Apr 19, 2017
1 parent 18749a6 commit 5915490
Show file tree
Hide file tree
Showing 33 changed files with 535 additions and 535 deletions.
16 changes: 8 additions & 8 deletions ast/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ func (ts *testFlagSuite) SetUpSuite(c *C) {

func (ts *testFlagSuite) TestHasAggFlag(c *C) {
expr := &ast.BetweenExpr{}
cases := []struct {
flagTests := []struct {
flag uint64
hasAgg bool
}{
{ast.FlagHasAggregateFunc, true},
{ast.FlagHasAggregateFunc | ast.FlagHasVariable, true},
{ast.FlagHasVariable, false},
}
for _, ca := range cases {
expr.SetFlag(ca.flag)
c.Assert(ast.HasAggFlag(expr), Equals, ca.hasAgg)
for _, tt := range flagTests {
expr.SetFlag(tt.flag)
c.Assert(ast.HasAggFlag(expr), Equals, tt.hasAgg)
}
}

func (ts *testFlagSuite) TestFlag(c *C) {
cases := []struct {
flagTests := []struct {
expr string
flag uint64
}{
Expand Down Expand Up @@ -114,12 +114,12 @@ func (ts *testFlagSuite) TestFlag(c *C) {
ast.FlagHasDefault,
},
}
for _, ca := range cases {
stmt, err := ts.ParseOneStmt("select "+ca.expr, "", "")
for _, tt := range flagTests {
stmt, err := ts.ParseOneStmt("select "+tt.expr, "", "")
c.Assert(err, IsNil)
selectStmt := stmt.(*ast.SelectStmt)
ast.SetFlag(selectStmt)
expr := selectStmt.Fields.Fields[0].Expr
c.Assert(expr.GetFlag(), Equals, ca.flag, Commentf("For %s", ca.expr))
c.Assert(expr.GetFlag(), Equals, tt.flag, Commentf("For %s", tt.expr))
}
}
12 changes: 6 additions & 6 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func (s *testColumnSuite) TestDropColumn(c *C) {
func (s *testColumnSuite) TestModifyColumn(c *C) {
d := newDDL(s.store, nil, nil, testLease)
defer d.Stop()
cases := []struct {
tests := []struct {
origin string
to string
err error
Expand All @@ -914,14 +914,14 @@ func (s *testColumnSuite) TestModifyColumn(c *C) {
{"varchar(10)", "varchar(11)", nil},
{"varchar(10) character set utf8 collate utf8_bin", "varchar(10) character set utf8", nil},
}
for _, ca := range cases {
ftA := s.colDefStrToFieldType(c, ca.origin)
ftB := s.colDefStrToFieldType(c, ca.to)
for _, tt := range tests {
ftA := s.colDefStrToFieldType(c, tt.origin)
ftB := s.colDefStrToFieldType(c, tt.to)
err := modifiable(ftA, ftB)
if err == nil {
c.Assert(ca.err, IsNil)
c.Assert(tt.err, IsNil)
} else {
c.Assert(err.Error(), Equals, ca.err.Error())
c.Assert(err.Error(), Equals, tt.err.Error())
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions distsql/xeval/eval_control_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *testEvalSuite) TestEvalCaseWhen(c *C) {
falseCond := types.NewIntDatum(0)
nullCond := types.Datum{}
nullCond.SetNull()
cases := []struct {
tests := []struct {
expr *tipb.Expr
result types.Datum
}{
Expand Down Expand Up @@ -73,11 +73,11 @@ func (s *testEvalSuite) TestEvalCaseWhen(c *C) {
result: types.NewStringDatum("case3"),
},
}
for _, ca := range cases {
result, err := xevaluator.Eval(ca.expr)
for _, tt := range tests {
result, err := xevaluator.Eval(tt.expr)
c.Assert(err, IsNil)
c.Assert(result.Kind(), Equals, ca.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, ca.result)
c.Assert(result.Kind(), Equals, tt.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, tt.result)
c.Assert(err, IsNil)
c.Assert(cmp, Equals, 0)
}
Expand All @@ -89,7 +89,7 @@ func (s *testEvalSuite) TestEvalIf(c *C) {
xevaluator.Row[colID] = types.NewIntDatum(100)
trueCond, falseCond, null := types.NewIntDatum(1), types.NewIntDatum(0), types.Datum{}
expr1, expr2 := types.NewStringDatum("expr1"), types.NewStringDatum("expr2")
cases := []struct {
tests := []struct {
expr *tipb.Expr
result types.Datum
}{
Expand Down Expand Up @@ -130,11 +130,11 @@ func (s *testEvalSuite) TestEvalIf(c *C) {
result: expr2,
},
}
for _, ca := range cases {
result, err := xevaluator.Eval(ca.expr)
for _, tt := range tests {
result, err := xevaluator.Eval(tt.expr)
c.Assert(err, IsNil)
c.Assert(result.Kind(), Equals, ca.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, ca.result)
c.Assert(result.Kind(), Equals, tt.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, tt.result)
c.Assert(err, IsNil)
c.Assert(cmp, Equals, 0)
}
Expand All @@ -145,7 +145,7 @@ func (s *testEvalSuite) TestEvalNullIf(c *C) {
xevaluator := NewEvaluator(new(variable.StatementContext))
xevaluator.Row[colID] = types.NewDatum(100)
null := types.Datum{}
cases := []struct {
tests := []struct {
expr *tipb.Expr
result types.Datum
}{
Expand All @@ -170,11 +170,11 @@ func (s *testEvalSuite) TestEvalNullIf(c *C) {
result: types.NewIntDatum(123),
},
}
for _, ca := range cases {
result, err := xevaluator.Eval(ca.expr)
for _, tt := range tests {
result, err := xevaluator.Eval(tt.expr)
c.Assert(err, IsNil)
c.Assert(result.Kind(), Equals, ca.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, ca.result)
c.Assert(result.Kind(), Equals, tt.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, tt.result)
c.Assert(err, IsNil)
c.Assert(cmp, Equals, 0)
}
Expand All @@ -185,7 +185,7 @@ func (s *testEvalSuite) TestEvalIfNull(c *C) {
xevaluator := NewEvaluator(new(variable.StatementContext))
xevaluator.Row[colID] = types.NewDatum(100)
null, notNull, expr := types.Datum{}, types.NewStringDatum("left"), types.NewStringDatum("right")
cases := []struct {
tests := []struct {
expr *tipb.Expr
result types.Datum
}{
Expand All @@ -205,11 +205,11 @@ func (s *testEvalSuite) TestEvalIfNull(c *C) {
result: notNull,
},
}
for _, ca := range cases {
result, err := xevaluator.Eval(ca.expr)
for _, tt := range tests {
result, err := xevaluator.Eval(tt.expr)
c.Assert(err, IsNil)
c.Assert(result.Kind(), Equals, ca.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, ca.result)
c.Assert(result.Kind(), Equals, tt.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, tt.result)
c.Assert(err, IsNil)
c.Assert(cmp, Equals, 0)
}
Expand Down
10 changes: 5 additions & 5 deletions distsql/xeval/eval_other_funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s *testEvalSuite) TestEvalCoalesce(c *C) {
nullDatum := types.Datum{}
nullDatum.SetNull()
notNullDatum := types.NewStringDatum("not-null")
cases := []struct {
tests := []struct {
expr *tipb.Expr
result types.Datum
}{
Expand All @@ -44,11 +44,11 @@ func (s *testEvalSuite) TestEvalCoalesce(c *C) {
result: notNullDatum,
},
}
for _, ca := range cases {
result, err := xevaluator.Eval(ca.expr)
for _, tt := range tests {
result, err := xevaluator.Eval(tt.expr)
c.Assert(err, IsNil)
c.Assert(result.Kind(), Equals, ca.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, ca.result)
c.Assert(result.Kind(), Equals, tt.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, tt.result)
c.Assert(err, IsNil)
c.Assert(cmp, Equals, 0)
}
Expand Down
38 changes: 19 additions & 19 deletions distsql/xeval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *testEvalSuite) TestEval(c *C) {
colID := int64(1)
xevaluator := NewEvaluator(new(variable.StatementContext))
xevaluator.Row[colID] = types.NewIntDatum(100)
cases := []struct {
tests := []struct {
expr *tipb.Expr
result types.Datum
}{
Expand Down Expand Up @@ -273,11 +273,11 @@ func (s *testEvalSuite) TestEval(c *C) {
types.NewFloat64Datum(1.1),
},
}
for _, ca := range cases {
result, err := xevaluator.Eval(ca.expr)
for _, tt := range tests {
result, err := xevaluator.Eval(tt.expr)
c.Assert(err, IsNil)
c.Assert(result.Kind(), Equals, ca.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, ca.result)
c.Assert(result.Kind(), Equals, tt.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, tt.result)
c.Assert(err, IsNil)
c.Assert(cmp, Equals, 0)
}
Expand Down Expand Up @@ -357,7 +357,7 @@ func notExpr(value interface{}) *tipb.Expr {
}

func (s *testEvalSuite) TestLike(c *C) {
cases := []struct {
tests := []struct {
expr *tipb.Expr
result int64
}{
Expand Down Expand Up @@ -407,15 +407,15 @@ func (s *testEvalSuite) TestLike(c *C) {
},
}
ev := NewEvaluator(new(variable.StatementContext))
for _, ca := range cases {
res, err := ev.Eval(ca.expr)
for _, tt := range tests {
res, err := ev.Eval(tt.expr)
c.Check(err, IsNil)
c.Check(res.GetInt64(), Equals, ca.result)
c.Check(res.GetInt64(), Equals, tt.result)
}
}

func (s *testEvalSuite) TestWhereIn(c *C) {
cases := []struct {
tests := []struct {
expr *tipb.Expr
result interface{}
}{
Expand Down Expand Up @@ -453,14 +453,14 @@ func (s *testEvalSuite) TestWhereIn(c *C) {
},
}
ev := NewEvaluator(new(variable.StatementContext))
for _, ca := range cases {
res, err := ev.Eval(ca.expr)
for _, tt := range tests {
res, err := ev.Eval(tt.expr)
c.Check(err, IsNil)
if ca.result == nil {
if tt.result == nil {
c.Check(res.Kind(), Equals, types.KindNull)
} else {
c.Check(res.Kind(), Equals, types.KindInt64)
if ca.result == true {
if tt.result == true {
c.Check(res.GetInt64(), Equals, int64(1))
} else {
c.Check(res.GetInt64(), Equals, int64(0))
Expand All @@ -474,7 +474,7 @@ func (s *testEvalSuite) TestEvalIsNull(c *C) {
xevaluator := NewEvaluator(new(variable.StatementContext))
xevaluator.Row[colID] = types.NewIntDatum(100)
null, trueAns, falseAns := types.Datum{}, types.NewIntDatum(1), types.NewIntDatum(0)
cases := []struct {
tests := []struct {
expr *tipb.Expr
result types.Datum
}{
Expand All @@ -491,11 +491,11 @@ func (s *testEvalSuite) TestEvalIsNull(c *C) {
result: falseAns,
},
}
for _, ca := range cases {
result, err := xevaluator.Eval(ca.expr)
for _, tt := range tests {
result, err := xevaluator.Eval(tt.expr)
c.Assert(err, IsNil)
c.Assert(result.Kind(), Equals, ca.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, ca.result)
c.Assert(result.Kind(), Equals, tt.result.Kind())
cmp, err := result.CompareDatum(xevaluator.StatementCtx, tt.result)
c.Assert(err, IsNil)
c.Assert(cmp, Equals, 0)
}
Expand Down
12 changes: 6 additions & 6 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (s *testSuite) TestStreamAgg(c *C) {
cntAgg := expression.NewAggFunction(ast.AggFuncCount, []expression.Expression{col}, false)
avgAgg := expression.NewAggFunction(ast.AggFuncAvg, []expression.Expression{col}, false)
maxAgg := expression.NewAggFunction(ast.AggFuncMax, []expression.Expression{col}, false)
cases := []struct {
tests := []struct {
aggFunc expression.AggregationFunction
result string
input [][]interface{}
Expand Down Expand Up @@ -359,28 +359,28 @@ func (s *testSuite) TestStreamAgg(c *C) {
},
}
ctx := mock.NewContext()
for _, ca := range cases {
for _, tt := range tests {
mock := &MockExec{}
e := &executor.StreamAggExec{
AggFuncs: []expression.AggregationFunction{ca.aggFunc},
AggFuncs: []expression.AggregationFunction{tt.aggFunc},
Src: mock,
StmtCtx: ctx.GetSessionVars().StmtCtx,
}
row, err := e.Next()
c.Check(err, IsNil)
c.Check(row, NotNil)
c.Assert(fmt.Sprintf("%v", row.Data[0].GetValue()), Equals, ca.result)
c.Assert(fmt.Sprintf("%v", row.Data[0].GetValue()), Equals, tt.result)
e.GroupByItems = append(e.GroupByItems, gbyCol)
e.Close()
row, err = e.Next()
c.Check(err, IsNil)
c.Check(row, IsNil)
e.Close()
for _, input := range ca.input {
for _, input := range tt.input {
data := types.MakeDatums(input...)
mock.Rows = append(mock.Rows, &executor.Row{Data: data})
}
for _, res := range ca.result1 {
for _, res := range tt.result1 {
row, err = e.Next()
c.Check(err, IsNil)
c.Check(row, NotNil)
Expand Down
Loading

0 comments on commit 5915490

Please sign in to comment.