Skip to content

Commit 98b631b

Browse files
committed
add more unit tests
Signed-off-by: Lonng <heng@lonng.org>
1 parent dc9cefb commit 98b631b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

expression/expr_to_pb_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,20 +605,30 @@ func (s *testEvaluatorSuite) TestImplicitParameters(c *C) {
605605

606606
pc := PbConverter{client: client, sc: sc}
607607

608-
// None flag
608+
// InUnion flag is false in `BuildCastFunction` when `ScalarFuncSig_CastStringAsInt`
609609
cast := BuildCastFunction(mock.NewContext(), dg.genColumn(mysql.TypeString, 1), types.NewFieldType(mysql.TypeLonglong))
610-
c.Assert(cast.(*ScalarFunction).Function.implicitParameters(), IsNil)
610+
c.Assert(cast.(*ScalarFunction).Function.implicitParameters(), DeepEquals, []types.Datum{types.NewIntDatum(0)})
611611
expr := pc.ExprToPB(sc, cast)
612612
c.Assert(expr.Sig, Equals, tipb.ScalarFuncSig_CastStringAsInt)
613+
c.Assert(len(expr.Val), Greater, 0)
614+
datums, err := codec.Decode(expr.Val, 1)
615+
c.Assert(err, IsNil)
616+
c.Assert(datums, DeepEquals, []types.Datum{types.NewIntDatum(0)})
617+
618+
// InUnion flag is nil in `BuildCastFunction4Union` when `ScalarFuncSig_CastIntAsString`
619+
castInUnion := BuildCastFunction4Union(mock.NewContext(), dg.genColumn(mysql.TypeLonglong, 1), types.NewFieldType(mysql.TypeString))
620+
c.Assert(castInUnion.(*ScalarFunction).Function.implicitParameters(), IsNil)
621+
expr = pc.ExprToPB(sc, castInUnion)
622+
c.Assert(expr.Sig, Equals, tipb.ScalarFuncSig_CastIntAsString)
613623
c.Assert(len(expr.Val), Equals, 0)
614624

615-
// InUnion flag
616-
castInUnion := BuildCastFunction4Union(mock.NewContext(), dg.genColumn(mysql.TypeString, 1), types.NewFieldType(mysql.TypeLonglong))
625+
// InUnion flag is true in `BuildCastFunction4Union` when `ScalarFuncSig_CastStringAsInt`
626+
castInUnion = BuildCastFunction4Union(mock.NewContext(), dg.genColumn(mysql.TypeString, 1), types.NewFieldType(mysql.TypeLonglong))
617627
c.Assert(castInUnion.(*ScalarFunction).Function.implicitParameters(), DeepEquals, []types.Datum{types.NewIntDatum(1)})
618628
expr = pc.ExprToPB(sc, castInUnion)
619629
c.Assert(expr.Sig, Equals, tipb.ScalarFuncSig_CastStringAsInt)
620630
c.Assert(len(expr.Val), Greater, 0)
621-
datums, err := codec.Decode(expr.Val, 1)
631+
datums, err = codec.Decode(expr.Val, 1)
622632
c.Assert(err, IsNil)
623633
c.Assert(datums, DeepEquals, []types.Datum{types.NewIntDatum(1)})
624634
}

0 commit comments

Comments
 (0)