github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/unary/ltrim_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  	"log"
    19  	"testing"
    20  
    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 Test_Ltrim(t *testing.T) {
    27  	convey.Convey("Test Ltrim succ", t, func() {
    28  		var charVecBase = []string{" 123", "  123", "123 ", " 8 ", " 8 a ", ""}
    29  		var nsp1 = []uint64{5}
    30  		var origVecs = make([]*vector.Vector, 1)
    31  		var proc = testutil.NewProc()
    32  		origVecs[0] = testutil.MakeCharVector(charVecBase, nsp1)
    33  		vec, err := Ltrim(origVecs, proc)
    34  		if err != nil {
    35  			log.Fatal(err)
    36  		}
    37  
    38  		data := vector.GetStrVectorValues(vec)
    39  		compVec := []string{"123", "123", "123 ", "8 ", "8 a ", ""}
    40  		compNsp := []int64{5}
    41  
    42  		for i := 0; i < len(compVec); i++ {
    43  			convey.So(data[i], convey.ShouldEqual, compVec[i])
    44  		}
    45  		j := 0
    46  		for i := 0; i < len(compVec); i++ {
    47  			if j < len(compNsp) {
    48  				if compNsp[j] == int64(i) {
    49  					convey.So(vec.Nsp.Np.Contains(uint64(i)), convey.ShouldBeTrue)
    50  					j++
    51  				} else {
    52  					convey.So(vec.Nsp.Np.Contains(uint64(i)), convey.ShouldBeFalse)
    53  				}
    54  			} else {
    55  				convey.So(vec.Nsp.Np.Contains(uint64(i)), convey.ShouldBeFalse)
    56  			}
    57  		}
    58  	})
    59  }