github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/util/util_test.go (about) 1 // Copyright 2021 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 util 16 17 import ( 18 "fmt" 19 "github.com/stretchr/testify/require" 20 "testing" 21 ) 22 23 type kase struct { 24 a string 25 b string 26 want string 27 wantErr bool 28 } 29 30 func Test_MakeNameOfPartitionTable(t *testing.T) { 31 kases := []kase{ 32 {partitionDelimiter, "abc", "", true}, 33 {"abc", partitionDelimiter, "", true}, 34 {"", "abc", "", true}, 35 {"abc", "", "", true}, 36 {"abc", "def", fmt.Sprintf("%sabc%sdef", partitionDelimiter, partitionDelimiter), false}, 37 } 38 39 for _, k := range kases { 40 r1, r11 := MakeNameOfPartitionTable(k.a, k.b) 41 if k.wantErr { 42 require.False(t, r1) 43 } else { 44 require.True(t, r1) 45 require.Equal(t, k.want, r11) 46 47 r2, a, b := SplitNameOfPartitionTable(r11) 48 require.True(t, r2) 49 require.Equal(t, a, k.a) 50 require.Equal(t, b, k.b) 51 } 52 } 53 } 54 55 func Test_SplitNameOfPartitionTable(t *testing.T) { 56 kases := []kase{ 57 {"", "", "abc", true}, 58 {"", "", partitionDelimiter + "abc", true}, 59 {"", "", partitionDelimiter, true}, 60 {"", "", partitionDelimiter + partitionDelimiter, true}, 61 {"", "", partitionDelimiter + "a" + partitionDelimiter, true}, 62 {"", "", partitionDelimiter + "" + partitionDelimiter + "b", true}, 63 {"a", "b", partitionDelimiter + "a" + partitionDelimiter + "b", false}, 64 } 65 66 for _, k := range kases { 67 r1, a, b := SplitNameOfPartitionTable(k.want) 68 if k.wantErr { 69 require.False(t, r1) 70 } else { 71 require.True(t, r1) 72 require.Equal(t, a, k.a) 73 require.Equal(t, b, k.b) 74 } 75 } 76 }