github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/schema/collation_comparator_test.go (about) 1 // Copyright 2023 Dolthub, 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 // 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 schema 16 17 import ( 18 "fmt" 19 "testing" 20 21 "github.com/dolthub/go-mysql-server/sql" 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestCompareCollatedStrings(t *testing.T) { 26 tests := []struct { 27 name string 28 left []byte 29 right []byte 30 exp int 31 }{ 32 { 33 left: []byte("Hello, 人"), 34 right: []byte("Hello, 亻"), 35 exp: -1, 36 }, 37 { 38 left: []byte("woÒ"), 39 right: []byte("woÓ"), 40 exp: 0, 41 }, 42 { 43 left: []byte("\u07FB"), 44 right: []byte("\u07FC"), 45 exp: -1, 46 }, 47 { 48 left: []byte("˧"), 49 right: []byte("˦"), 50 exp: 1, 51 }, 52 { 53 left: []byte("ƵƶzƸ"), 54 right: []byte("ƵƶzƷ"), 55 exp: 1, 56 }, 57 } 58 59 for _, tt := range tests { 60 t.Run(fmt.Sprintf("%s vs %s", tt.left, tt.right), func(t *testing.T) { 61 cmp := compareCollatedStrings(sql.Collation_utf8mb4_0900_ai_ci, tt.left, tt.right) 62 require.Equal(t, tt.exp, cmp) 63 }) 64 } 65 }