github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/unary/reverse_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 TestReverse(t *testing.T) {
    27  	convey.Convey("right", t, func() {
    28  		inputStrs := []string{
    29  			"abc",
    30  			"abcd",
    31  			"hello",
    32  			"アイウエオ",
    33  			"あいうえお",
    34  			"龔龖龗龞龡",
    35  			"你好",
    36  			"再 见",
    37  			"bcd",
    38  			"def",
    39  			"xyz",
    40  			"1a1",
    41  			"2012",
    42  			"@($)@($#)_@(#",
    43  			"2023-04-24",
    44  			"10:03:23.021412",
    45  			"sdfad  ",
    46  		}
    47  		wantStrs := []string{
    48  			"cba",
    49  			"dcba",
    50  			"olleh",
    51  			"オエウイア",
    52  			"おえういあ",
    53  			"龡龞龗龖龔",
    54  			"好你",
    55  			"见 再",
    56  			"dcb",
    57  			"fed",
    58  			"zyx",
    59  			"1a1",
    60  			"2102",
    61  			"#(@_)#$(@)$(@",
    62  			"42-40-3202",
    63  			"214120.32:30:01",
    64  			"  dafds",
    65  		}
    66  		ivec := testutil.MakeVarcharVector(inputStrs, nil)
    67  		wantVec := testutil.MakeVarcharVector(wantStrs, nil)
    68  		proc := testutil.NewProc()
    69  		get, err := Reverse([]*vector.Vector{ivec}, proc)
    70  		convey.So(err, convey.ShouldBeNil)
    71  		ret := testutil.CompareVectors(wantVec, get)
    72  		convey.So(ret, convey.ShouldBeTrue)
    73  	})
    74  
    75  	convey.Convey("null", t, func() {
    76  		ivec := testutil.MakeScalarNull(types.T_char, 10)
    77  		wantvec := testutil.MakeScalarNull(types.T_char, 10)
    78  		proc := testutil.NewProc()
    79  		ovec, err := Reverse([]*vector.Vector{ivec}, proc)
    80  		convey.So(err, convey.ShouldBeNil)
    81  		ret := testutil.CompareVectors(wantvec, ovec)
    82  		convey.So(ret, convey.ShouldBeTrue)
    83  
    84  	})
    85  }