github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/trim_test.go (about) 1 package functions 2 3 import "testing" 4 5 func Test_Trim(t *testing.T) { 6 tests := []struct { 7 name string 8 args []interface{} 9 expected string 10 }{ 11 { 12 name: "trim a string", 13 args: []interface{}{ 14 " hello ", 15 }, 16 expected: "hello", 17 }, 18 { 19 name: "trim a string with multiple spaces", 20 args: []interface{}{ 21 " hello ", 22 }, 23 expected: "hello", 24 }, 25 { 26 name: "trim a string with tabs", 27 args: []interface{}{ 28 " hello ", 29 }, 30 expected: "hello", 31 }, 32 { 33 name: "trim a string with new lines", 34 args: []interface{}{ 35 ` 36 37 hello 38 39 `, 40 }, 41 expected: "hello", 42 }, 43 { 44 name: "trim a string with tabs, spaces and new lines", 45 args: []interface{}{ 46 ` 47 48 hello 49 50 `, 51 }, 52 expected: "hello", 53 }, 54 { 55 name: "trim a string with non string input", 56 args: []interface{}{ 57 10, 58 }, 59 expected: "", 60 }, 61 } 62 63 for _, tt := range tests { 64 t.Run(tt.name, func(t *testing.T) { 65 actual := Trim(tt.args...) 66 if actual != tt.expected { 67 t.Errorf("Trim(%v) = %v, expected %v", tt.args, actual, tt.expected) 68 } 69 }) 70 } 71 }