github.com/matrixorigin/matrixone@v1.2.0/pkg/vectorize/instr/instr_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 instr 16 17 import ( 18 "testing" 19 ) 20 21 func TestSingle(t *testing.T) { 22 kases := []struct { 23 str string 24 sub string 25 ret int64 26 }{ 27 {"abc", "bc", 2}, 28 {"abc", "b", 2}, 29 {"abc", "A", 1}, 30 {"abc", "abc", 1}, 31 {"foobarbar", "bar", 4}, 32 {"foobarbar", "Bar", 4}, 33 {"Abc", "A", 1}, 34 {"abc", "A", 1}, 35 {"abc", "a", 1}, 36 {"abc", "dca", 0}, 37 {"abc", "", 1}, 38 {"", "abc", 0}, 39 {"", "", 1}, 40 {"abc", "abcabc", 0}, 41 {"abcabc", "abc", 1}, 42 {"abcabc", "bc", 2}, 43 {"啊撒撒撒撒", "啊", 1}, 44 {"啊撒撒撒撒", "撒", 2}, 45 {"啊撒撒撒撒", "撒撒", 2}, 46 {"啊撒撒撒撒x的q", "x", 6}, 47 {"啊撒撒撒撒x的q", "x的", 6}, 48 {"啊撒撒撒撒x的q", "x的q", 6}, 49 {"啊撒撒撒撒x的q", "x的q啊", 0}, 50 {"啊撒撒撒撒x的q", "的", 7}, 51 {"啊撒撒撒撒x的q", "的q", 7}, 52 {"啊撒撒撒撒x的q", "的q啊", 0}, 53 {"啊撒撒撒撒x的q", "q", 8}, 54 } 55 for _, kase := range kases { 56 ret := Single(kase.str, kase.sub) 57 if ret != kase.ret { 58 t.Fatalf("str: %s, sub: %s, ret: %d, want: %d", kase.str, kase.sub, ret, kase.ret) 59 } 60 } 61 }