github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/substring_test.go (about) 1 package functions 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_SubString(t *testing.T) { 10 11 tests := []struct { 12 name string 13 args []interface{} 14 expected string 15 }{ 16 { 17 name: "substring a string", 18 args: []interface{}{ 19 "hello", 20 1, 21 3, 22 }, 23 expected: "ell", 24 }, 25 { 26 name: "substring a string with no upper bound", 27 args: []interface{}{ 28 "hello", 29 1, 30 }, 31 expected: "ello", 32 }, 33 { 34 name: "substring a string with start higher than the length", 35 args: []interface{}{ 36 "hello", 37 10, 38 }, 39 expected: "", 40 }, 41 } 42 43 for _, tt := range tests { 44 t.Run(tt.name, func(t *testing.T) { 45 actual := SubString(tt.args...) 46 assert.Equal(t, tt.expected, actual) 47 }) 48 } 49 }