github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/interlock/collation_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package interlock 15 16 import ( 17 . "github.com/whtcorpsinc/check" 18 "github.com/whtcorpsinc/BerolinaSQL/allegrosql" 19 "github.com/whtcorpsinc/milevadb/memex" 20 "github.com/whtcorpsinc/milevadb/types" 21 "github.com/whtcorpsinc/milevadb/soliton/chunk" 22 "github.com/whtcorpsinc/milevadb/soliton/defCauslate" 23 "github.com/whtcorpsinc/milevadb/soliton/mock" 24 ) 25 26 var _ = SerialSuites(&testDefCauslationSuite{}) 27 28 type testDefCauslationSuite struct { 29 } 30 31 func (s *testDefCauslationSuite) TestVecGroupChecker(c *C) { 32 defCauslate.SetNewDefCauslationEnabledForTest(true) 33 defer defCauslate.SetNewDefCauslationEnabledForTest(false) 34 35 tp := &types.FieldType{Tp: allegrosql.TypeVarchar} 36 defCaus0 := &memex.DeferredCauset{ 37 RetType: tp, 38 Index: 0, 39 } 40 ctx := mock.NewContext() 41 groupChecker := newVecGroupChecker(ctx, []memex.Expression{defCaus0}) 42 43 chk := chunk.New([]*types.FieldType{tp}, 6, 6) 44 chk.Reset() 45 chk.DeferredCauset(0).AppendString("aaa") 46 chk.DeferredCauset(0).AppendString("AAA") 47 chk.DeferredCauset(0).AppendString("😜") 48 chk.DeferredCauset(0).AppendString("😃") 49 chk.DeferredCauset(0).AppendString("À") 50 chk.DeferredCauset(0).AppendString("A") 51 52 tp.DefCauslate = "bin" 53 groupChecker.reset() 54 _, err := groupChecker.splitIntoGroups(chk) 55 c.Assert(err, IsNil) 56 for i := 0; i < 6; i++ { 57 b, e := groupChecker.getNextGroup() 58 c.Assert(b, Equals, i) 59 c.Assert(e, Equals, i+1) 60 } 61 c.Assert(groupChecker.isExhausted(), IsTrue) 62 63 tp.DefCauslate = "utf8_general_ci" 64 groupChecker.reset() 65 _, err = groupChecker.splitIntoGroups(chk) 66 c.Assert(err, IsNil) 67 for i := 0; i < 3; i++ { 68 b, e := groupChecker.getNextGroup() 69 c.Assert(b, Equals, i*2) 70 c.Assert(e, Equals, i*2+2) 71 } 72 c.Assert(groupChecker.isExhausted(), IsTrue) 73 74 tp.DefCauslate = "utf8_unicode_ci" 75 groupChecker.reset() 76 _, err = groupChecker.splitIntoGroups(chk) 77 c.Assert(err, IsNil) 78 for i := 0; i < 3; i++ { 79 b, e := groupChecker.getNextGroup() 80 c.Assert(b, Equals, i*2) 81 c.Assert(e, Equals, i*2+2) 82 } 83 c.Assert(groupChecker.isExhausted(), IsTrue) 84 85 // test padding 86 tp.DefCauslate = "utf8_bin" 87 tp.Flen = 6 88 chk.Reset() 89 chk.DeferredCauset(0).AppendString("a") 90 chk.DeferredCauset(0).AppendString("a ") 91 chk.DeferredCauset(0).AppendString("a ") 92 groupChecker.reset() 93 _, err = groupChecker.splitIntoGroups(chk) 94 c.Assert(err, IsNil) 95 b, e := groupChecker.getNextGroup() 96 c.Assert(b, Equals, 0) 97 c.Assert(e, Equals, 3) 98 c.Assert(groupChecker.isExhausted(), IsTrue) 99 }