github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/unary/rtrim_test.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package unary 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/testutil" 23 "github.com/smartystreets/goconvey/convey" 24 ) 25 26 func TestRtrim(t *testing.T) { 27 convey.Convey("right cases", t, func() { 28 type kase struct { 29 s string 30 want string 31 } 32 33 kases := []kase{ 34 { 35 "barbar ", 36 "barbar", 37 }, 38 { 39 "MySQL", 40 "MySQL", 41 }, 42 { 43 "a", 44 "a", 45 }, 46 { 47 " 20.06 ", 48 " 20.06", 49 }, 50 { 51 " right ", 52 " right", 53 }, 54 { 55 "你好 ", 56 "你好", 57 }, 58 { 59 "2017-06-15 ", 60 "2017-06-15", 61 }, 62 { 63 "2017-06-15 ", 64 "2017-06-15", 65 }, 66 } 67 68 var inStrs []string 69 var outStrs []string 70 for _, k := range kases { 71 inStrs = append(inStrs, k.s) 72 outStrs = append(outStrs, k.want) 73 } 74 75 extraInStrs := []string{ 76 "アイウエオ", 77 "アイウエオ ", 78 "アイウエオ ", 79 "アイウエオ ", 80 "アイウエオ ", 81 "アイウエオ ", 82 "アイウエオ ", 83 "あいうえお", 84 "あいうえお ", 85 "あいうえお ", 86 "あいうえお ", 87 "あいうえお", 88 "あいうえお ", 89 "あいうえお ", 90 "龔龖龗龞龡", 91 "龔龖龗龞龡 ", 92 "龔龖龗龞龡 ", 93 "龔龖龗龞龡 ", 94 "龔龖龗龞龡", 95 "龔龖龗龞龡 ", 96 "龔龖龗龞龡 ", 97 "アイウエオ", 98 "アイウエオ ", 99 "アイウエオ ", 100 "アイウエオ ", 101 "アイウエオ", 102 "アイウエオ ", 103 "アイウエオ ", 104 "あいうえお", 105 "あいうえお ", 106 "あいうえお ", 107 "あいうえお ", 108 "あいうえお", 109 "あいうえお ", 110 "あいうえお ", 111 "龔龖龗龞龡", 112 "龔龖龗龞龡 ", 113 "龔龖龗龞龡 ", 114 "龔龖龗龞龡 ", 115 "龔龖龗龞龡", 116 "龔龖龗龞龡 ", 117 "龔龖龗龞龡 ", 118 "アイウエオ", 119 "アイウエオ ", 120 "アイウエオ ", 121 "アイウエオ ", 122 "アイウエオ", 123 "アイウエオ ", 124 "アイウエオ ", 125 "あいうえお", 126 "あいうえお ", 127 "あいうえお ", 128 "あいうえお ", 129 "あいうえお", 130 "あいうえお ", 131 "あいうえお ", 132 "龔龖龗龞龡", 133 "龔龖龗龞龡 ", 134 "龔龖龗龞龡 ", 135 "龔龖龗龞龡 ", 136 "龔龖龗龞龡", 137 "龔龖龗龞龡 ", 138 "龔龖龗龞龡 ", 139 "2017-06-15 ", 140 "2019-06-25 ", 141 " 2019-06-25 ", 142 " 2019-06-25 ", 143 " 2012-10-12 ", 144 " 2004-04-24. ", 145 " 2008-12-04. ", 146 " 2012-03-23. ", 147 " 2013-04-30 ", 148 " 1994-10-04 ", 149 " 2018-06-04 ", 150 " 2012-10-12 ", 151 "1241241^&@%#^*^!@#&*(!& ", 152 " 123 ", 153 } 154 extraOutStrs := []string{ 155 "アイウエオ", 156 "アイウエオ", 157 "アイウエオ", 158 "アイウエオ", 159 "アイウエオ", 160 "アイウエオ", 161 "アイウエオ", 162 "あいうえお", 163 "あいうえお", 164 "あいうえお", 165 "あいうえお", 166 "あいうえお", 167 "あいうえお", 168 "あいうえお", 169 "龔龖龗龞龡", 170 "龔龖龗龞龡", 171 "龔龖龗龞龡", 172 "龔龖龗龞龡", 173 "龔龖龗龞龡", 174 "龔龖龗龞龡", 175 "龔龖龗龞龡", 176 "アイウエオ", 177 "アイウエオ", 178 "アイウエオ", 179 "アイウエオ", 180 "アイウエオ", 181 "アイウエオ", 182 "アイウエオ", 183 "あいうえお", 184 "あいうえお", 185 "あいうえお", 186 "あいうえお", 187 "あいうえお", 188 "あいうえお", 189 "あいうえお", 190 "龔龖龗龞龡", 191 "龔龖龗龞龡", 192 "龔龖龗龞龡", 193 "龔龖龗龞龡", 194 "龔龖龗龞龡", 195 "龔龖龗龞龡", 196 "龔龖龗龞龡", 197 "アイウエオ", 198 "アイウエオ", 199 "アイウエオ", 200 "アイウエオ", 201 "アイウエオ", 202 "アイウエオ", 203 "アイウエオ", 204 "あいうえお", 205 "あいうえお", 206 "あいうえお", 207 "あいうえお", 208 "あいうえお", 209 "あいうえお", 210 "あいうえお", 211 "龔龖龗龞龡", 212 "龔龖龗龞龡", 213 "龔龖龗龞龡", 214 "龔龖龗龞龡", 215 "龔龖龗龞龡", 216 "龔龖龗龞龡", 217 "龔龖龗龞龡", 218 "2017-06-15", 219 "2019-06-25", 220 " 2019-06-25", 221 " 2019-06-25", 222 " 2012-10-12", 223 " 2004-04-24.", 224 " 2008-12-04.", 225 " 2012-03-23.", 226 " 2013-04-30", 227 " 1994-10-04", 228 " 2018-06-04", 229 " 2012-10-12", 230 "1241241^&@%#^*^!@#&*(!&", 231 " 123", 232 } 233 234 inStrs = append(inStrs, extraInStrs...) 235 outStrs = append(outStrs, extraOutStrs...) 236 237 ivec := testutil.MakeVarcharVector(inStrs, nil) 238 wantVec := testutil.MakeVarcharVector(outStrs, nil) 239 proc := testutil.NewProc() 240 retVec, err := Rtrim([]*vector.Vector{ivec}, proc) 241 convey.So(err, convey.ShouldBeNil) 242 ret := testutil.CompareVectors(wantVec, retVec) 243 convey.So(ret, convey.ShouldBeTrue) 244 }) 245 convey.Convey("null", t, func() { 246 ivec := testutil.MakeScalarNull(types.T_char, 10) 247 wantvec := testutil.MakeScalarNull(types.T_char, 10) 248 proc := testutil.NewProc() 249 ovec, err := Rtrim([]*vector.Vector{ivec}, proc) 250 convey.So(err, convey.ShouldBeNil) 251 ret := testutil.CompareVectors(wantvec, ovec) 252 convey.So(ret, convey.ShouldBeTrue) 253 254 }) 255 256 convey.Convey("scalar", t, func() { 257 ivec := testutil.MakeScalarVarchar("abc ", 5) 258 wantvec := testutil.MakeScalarVarchar("abc", 5) 259 proc := testutil.NewProc() 260 ovec, err := Rtrim([]*vector.Vector{ivec}, proc) 261 convey.So(err, convey.ShouldBeNil) 262 ret := testutil.CompareVectors(wantvec, ovec) 263 convey.So(ret, convey.ShouldBeTrue) 264 }) 265 }