Skip to content

Commit

Permalink
feat(test): add unit test for cast function
Browse files Browse the repository at this point in the history
  • Loading branch information
dongzl committed Jul 26, 2023
1 parent fae5d4e commit 21805cc
Showing 1 changed file with 2 additions and 44 deletions.
46 changes: 2 additions & 44 deletions pkg/runtime/function/cast_decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestCastDecimal(t *testing.T) {
}
}

func TestCastDecimal_Inputs_Error(t *testing.T) {
func TestCastDecimal_Inputs_length_Error(t *testing.T) {
fn := proto.MustGetFunc(FuncCastDecimal)
assert.Equal(t, 3, fn.NumInput())

Expand Down Expand Up @@ -108,7 +108,7 @@ func TestCastDecimal_Inputs_0_Error(t *testing.T) {
}
}

func TestCastDecimal_Inputs_1_Error(t *testing.T) {
func TestCastDecimal_Inputs_Error(t *testing.T) {
fn := proto.MustGetFunc(FuncCastDecimal)
assert.Equal(t, 3, fn.NumInput())

Expand All @@ -121,49 +121,7 @@ func TestCastDecimal_Inputs_1_Error(t *testing.T) {

for _, it := range []tt{
{proto.NewValueInt64(15), proto.NewValueString("a"), proto.NewValueInt64(2), "0"},
} {
t.Run(it.out, func(t *testing.T) {
out, err := fn.Apply(context.Background(), proto.ToValuer(it.inFirst), proto.ToValuer(it.inSecond), proto.ToValuer(it.intThird))
assert.Error(t, err)
assert.Nil(t, out)
})
}
}

func TestCastDecimal_Inputs_2_Error(t *testing.T) {
fn := proto.MustGetFunc(FuncCastDecimal)
assert.Equal(t, 3, fn.NumInput())

type tt struct {
inFirst proto.Value
inSecond proto.Value
intThird proto.Value
out string
}

for _, it := range []tt{
{proto.NewValueInt64(15), proto.NewValueInt64(4), proto.NewValueString("a"), "0"},
} {
t.Run(it.out, func(t *testing.T) {
out, err := fn.Apply(context.Background(), proto.ToValuer(it.inFirst), proto.ToValuer(it.inSecond), proto.ToValuer(it.intThird))
assert.Error(t, err)
assert.Nil(t, out)
})
}
}

func TestCastDecimal_Error(t *testing.T) {
fn := proto.MustGetFunc(FuncCastDecimal)
assert.Equal(t, 3, fn.NumInput())

type tt struct {
inFirst proto.Value
inSecond proto.Value
intThird proto.Value
out string
}

for _, it := range []tt{
{proto.NewValueInt64(15), proto.NewValueInt64(4), proto.NewValueInt64(5), "0"},
} {
t.Run(it.out, func(t *testing.T) {
Expand Down

0 comments on commit 21805cc

Please sign in to comment.