Skip to content

Commit

Permalink
evaluator: Add tests for funcCall.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyanzhe committed Dec 21, 2015
1 parent a5b5fd6 commit a5dbd00
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions optimizer/evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/expression/builtin"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/opcode"
Expand Down Expand Up @@ -382,6 +384,30 @@ func (s *testEvaluatorSuite) TestConvert(c *C) {
}
}

func (s *testEvaluatorSuite) TestCall(c *C) {
// To test this case, we need to fake a wrong builtin.Funcs
builtin.Funcs = map[string]builtin.Func{
"date": {nil, 8, 8, false, false},
}
ctx := mock.NewContext()

// Test case for unknown function
expr := &ast.FuncCallExpr{
FnName: model.NewCIStr("unknown"),
Args: []ast.ExprNode{},
}
_, err := Eval(ctx, expr)
c.Assert(err, NotNil)

// Test case for invalid number of arguments
expr = &ast.FuncCallExpr{
FnName: model.NewCIStr("date"),
Args: []ast.ExprNode{},
}
_, err = Eval(ctx, expr)
c.Assert(err, NotNil)
}

func (s *testEvaluatorSuite) TestCast(c *C) {
f := types.NewFieldType(mysql.TypeLonglong)

Expand Down

0 comments on commit a5dbd00

Please sign in to comment.