github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/s3select/sql/stringfuncs_contrib_test.go (about) 1 /* 2 * MinIO Object Storage (c) 2021 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package sql 18 19 import "testing" 20 21 func TestEvalSQLSubstring(t *testing.T) { 22 evalCases := []struct { 23 s string 24 startIdx int 25 length int 26 resExpected string 27 errExpected error 28 }{ 29 {"abcd", 1, 1, "a", nil}, 30 {"abcd", -1, 1, "a", nil}, 31 {"abcd", 999, 999, "", nil}, 32 {"", 999, 999, "", nil}, 33 {"测试abc", 1, 1, "测", nil}, 34 {"测试abc", 5, 5, "c", nil}, 35 } 36 37 for i, tc := range evalCases { 38 res, err := evalSQLSubstring(tc.s, tc.startIdx, tc.length) 39 if res != tc.resExpected || err != tc.errExpected { 40 t.Errorf("Eval Case %d failed: %v %v", i, res, err) 41 } 42 } 43 }