forked from matrixorigin/matrixone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring rtrim (matrixorigin#2922)
- Loading branch information
Showing
6 changed files
with
310 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,272 @@ | ||
package unary | ||
|
||
import ( | ||
"github.com/matrixorigin/matrixone/pkg/container/vector" | ||
"github.com/matrixorigin/matrixone/pkg/sql/testutil" | ||
"github.com/smartystreets/goconvey/convey" | ||
"testing" | ||
) | ||
|
||
func TestRtrim(t *testing.T) { | ||
convey.Convey("right cases", t, func() { | ||
type kase struct { | ||
s string | ||
want string | ||
} | ||
|
||
kases := []kase{ | ||
{ | ||
"barbar ", | ||
"barbar", | ||
}, | ||
{ | ||
"MySQL", | ||
"MySQL", | ||
}, | ||
{ | ||
"a", | ||
"a", | ||
}, | ||
{ | ||
" 20.06 ", | ||
" 20.06", | ||
}, | ||
{ | ||
" right ", | ||
" right", | ||
}, | ||
{ | ||
"你好 ", | ||
"你好", | ||
}, | ||
{ | ||
"2017-06-15 ", | ||
"2017-06-15", | ||
}, | ||
{ | ||
"2017-06-15 ", | ||
"2017-06-15", | ||
}, | ||
} | ||
|
||
var inStrs []string | ||
var outStrs []string | ||
for _, k := range kases { | ||
inStrs = append(inStrs, k.s) | ||
outStrs = append(outStrs, k.want) | ||
} | ||
|
||
extraInStrs := []string{ | ||
"アイウエオ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"あいうえお", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"アイウエオ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"あいうえお", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"アイウエオ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"アイウエオ ", | ||
"あいうえお", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"あいうえお ", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"龔龖龗龞龡 ", | ||
"2017-06-15 ", | ||
"2019-06-25 ", | ||
" 2019-06-25 ", | ||
" 2019-06-25 ", | ||
" 2012-10-12 ", | ||
" 2004-04-24. ", | ||
" 2008-12-04. ", | ||
" 2012-03-23. ", | ||
" 2013-04-30 ", | ||
" 1994-10-04 ", | ||
" 2018-06-04 ", | ||
" 2012-10-12 ", | ||
"1241241^&@%#^*^!@#&*(!& ", | ||
" 123 ", | ||
} | ||
extraOutStrs := []string{ | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"アイウエオ", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"あいうえお", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"龔龖龗龞龡", | ||
"2017-06-15", | ||
"2019-06-25", | ||
" 2019-06-25", | ||
" 2019-06-25", | ||
" 2012-10-12", | ||
" 2004-04-24.", | ||
" 2008-12-04.", | ||
" 2012-03-23.", | ||
" 2013-04-30", | ||
" 1994-10-04", | ||
" 2018-06-04", | ||
" 2012-10-12", | ||
"1241241^&@%#^*^!@#&*(!&", | ||
" 123", | ||
} | ||
|
||
inStrs = append(inStrs, extraInStrs...) | ||
outStrs = append(outStrs, extraOutStrs...) | ||
|
||
ivec := testutil.MakeVarcharVector(inStrs, nil) | ||
wantVec := testutil.MakeVarcharVector(outStrs, nil) | ||
proc := testutil.NewProc() | ||
retVec, err := Rtrim([]*vector.Vector{ivec}, proc) | ||
convey.So(err, convey.ShouldBeNil) | ||
ret := testutil.CompareVectors(wantVec, retVec) | ||
convey.So(ret, convey.ShouldBeTrue) | ||
}) | ||
convey.Convey("null", t, func() { | ||
ivec := testutil.MakeScalarNull(10) | ||
wantvec := testutil.MakeScalarNull(10) | ||
proc := testutil.NewProc() | ||
ovec, err := Rtrim([]*vector.Vector{ivec}, proc) | ||
convey.So(err, convey.ShouldBeNil) | ||
ret := testutil.CompareVectors(wantvec, ovec) | ||
convey.So(ret, convey.ShouldBeTrue) | ||
|
||
}) | ||
convey.Convey("tinyint", t, func() { | ||
ivec := testutil.MakeInt8Vector([]int8{ | ||
1, 71, 1, 1}, nil) | ||
proc := testutil.NewProc() | ||
_, err := Rtrim([]*vector.Vector{ivec}, proc) | ||
convey.So(err, convey.ShouldNotBeNil) | ||
|
||
ivec2 := testutil.MakeScalarInt8(1, 10) | ||
_, err = Rtrim([]*vector.Vector{ivec2}, proc) | ||
convey.So(err, convey.ShouldNotBeNil) | ||
}) | ||
|
||
convey.Convey("nil", t, func() { | ||
proc := testutil.NewProc() | ||
_, err := Rtrim([]*vector.Vector{}, proc) | ||
convey.So(err, convey.ShouldNotBeNil) | ||
|
||
_, err = Rtrim([]*vector.Vector{}, nil) | ||
convey.So(err, convey.ShouldNotBeNil) | ||
|
||
_, err = Rtrim([]*vector.Vector{nil}, proc) | ||
convey.So(err, convey.ShouldNotBeNil) | ||
}) | ||
|
||
convey.Convey("scalar", t, func() { | ||
ivec := testutil.MakeScalarVarchar("abc ", 5) | ||
wantvec := testutil.MakeScalarVarchar("abc", 5) | ||
proc := testutil.NewProc() | ||
ovec, err := Rtrim([]*vector.Vector{ivec}, proc) | ||
convey.So(err, convey.ShouldBeNil) | ||
ret := testutil.CompareVectors(wantvec, ovec) | ||
convey.So(ret, convey.ShouldBeTrue) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.